************************************************************************
*                     Administration: User Monitor                     *
*                                                                      *
*                Users overview in specified R/3 client                *
*   By default, only dialog users (excluding built-in) will be shown   *
*               Current version: 0366+ Date: 26-Aug-2008               *
*                                                                      *
*                  Developed on SAP R/3 Release 4.6C                   *
*                                                                      *
*      Responsible person: Alexander Redchenko, logon name: ARED       *
*                                                                      *
*           Click header line to reorder initial output list           *
*             Click activity icon to send a popup message              *
*     Click logon name to view/maintain user master record via SU01    *
*        Click any other field to display specific user activity,      *
*      analyze single statistical records and authorization trace      *
*       Click SESSIONS button to view system-wide users activity       *
*                                                                      *
*   To control additional security checks performed by this report     *
*   you should set up or reset the following hard-coded constants:     *
*                                                                      *
*       enable_chk1 value 'X' "Check for preset administrators         *
*       enable_chk2 value 'X' "Check entries in table ZAUTHLST         *
*                                                                      *
************************************************************************
report zusrmon message-id z2               "Default message class is Z2
               line-size 255               "The width of the output list
               no standard page heading    "Custom header will be used
               .
tables:                                    "Table work areas
  usr02       "Logon data
, usr07       "Object/values of last authorization check that failed
, usr41       "User master: Additional data
* t247        "Month name and short text
, sscrfields  "Fields on selection screens
* progdir     "Program attributes (view)
.
types:
  ty_func              like tfdir-funcname
, ty_tcode             like sy-tcode

, begin of tt_func
,   name               like tfdir-funcname
,   exists             type c
, end   of tt_func

*-See more information about Task Handlers at include TSKHINCL
, th_opcode(1)         type x
.
constants:
* Constants for calls of the ThSysInfo
  opcode_saprel        type th_opcode value  5 "SAP Release

* Constants for calls of the ThUsrInfo
, opcode_long_blk_info type th_opcode value  4 "User Memory in Details
, opcode_usr_attr      type th_opcode value  5 "User Attributes
, opcode_create_slave  type th_opcode value 14 "Create Slave Mode
, opcode_remove_slave  type th_opcode value 15 "Remove Slave Mode

* It is not clear why this const is requested, but... ;-)
, slave_mode           type th_opcode value  5 "Slave Mode

*-Lock state flags. For more details see include USER_CONSTANTS
, c_not_locked             type x value  '0' "User not locked
, c_locked_by_global_admin type x value '20' "Locked by global admin
, c_locked_by_admin        type x value '40' "Locked by admin
, c_locked_by_failed_logon type x value '80' "Locked by failed logon

, occ_val   type     i    value  500       "Int. tables occurs value
, d_mask(10)              value '__.__.____' "Date mask
, t_mask(8)               value '__:__:__' "Time mask
, t_mask2   like t_mask   value '........' "Time mask 'Not Available'
, c_saprl   like sy-saprl value '46B'      "SAP Release check value
, dot3(3)                 value '...'
, amp(1)                  value '&'        "For macro 'REPL'
, amp1(2)                 value '&1'       "For macro 'REPL2'
, amp2(2)                 value '&2'       "For macro 'REPL2'

, c_fld like dd03l-fieldname value 'DIFF'  "Default sorting field

, c_date1 like sy-datum value '00010101'   "01.01.0001 Anno Domini
* c_date2 like sy-datum value '99991231'   "31.12.9999 End of Time

*-Icons
, d_icon1       like icon-id value '@5B@'  "ICON_LED_GREEN
, d_icon2       like icon-id value '@AA@'  "ICON_RELATIONSHIP
*                                  '@BZ@'  "ICON_LED_INACTIVE
*                                  '@5D@'  "ICON_LED_YELLOW
*                                  '@HM@'  "ICON_PS_MILESTONE
*                                  '@4W@'  "ICON_BUSINAV_OBJECTS
, icon_ok       like icon-id value '@5B@'  "ICON_LED_GREEN
, icon_failed   like icon-id value '@5C@'  "ICON_LED_RED
, icon_active   like icon-id value '@5B@'  " 5B or BF
, icon_inactive like icon-id value '@5C@'  " 5C or BG

*-Miscellaneous
, loctab      like dd02l-tabname   value 'ZLOCATION'
, histtab     like dd03l-tabname   value 'ZUSR07'
, msg_tabn    like dd03l-tabname   value 'WPTOTLICER'
, msg_fldn    like dd03l-fieldname value 'COM_ERROR'
, idxkey      like indx-srtfd      value 'ZUSRMON_MSG' "Last message id
, key_vnc(10)                      value 'VNC'
, key_phones  like key_vnc         value 'PHONES2'
, key_photos  like key_vnc         value 'PHOTOS'
, arfc_max    like sy-index        value  9
, arfc_min    like sy-index        value  1
, cmd_tag(1)                       value '$'
*-Authorization Objects
, obj_sysadm  like tobj-objct      value 'S_ADMI_FCD'
, obj_usradm  like obj_sysadm      value 'S_USER_GRP'
.
*-Users to exclude from mass locking/unlocking
ranges
  avoid for usr02-bname occurs 10
.
data:
  head_to     like sy-staro    value   3   "Header Top (CMDL ctrl symb)
, head_ce     like sy-staro    value   4   "Header Center     (MAIN)
, head_bo     like sy-staro    value   5   "Header Bottom Row (MAIN)
, head_bo_s   like sy-staro    value   3   "Header Bottom Row (SESSIONS)

, tmp_bname   like usr02-bname value 'ZZZ' "Temporary user name
, point_bname like usr02-bname      "User ID to highlight
, f_group                           "Additional selection criteria
, f_chkaddr   value ' '             "Check users without address data
, f_keep      value ' '             "Keep list filtered after refresh
, f_histtab                         "History table exists
, f_pwdinfo                         "Info about password change date
, f_sele      value space           "Checkbox ALL/NONE   in MAIN
, f_sele_s    value space           "Checkbox ALL/NONE   in SESS
, f_extr      value space           "Show Extra Sessions in SESS
, f_toolbar   value space           "Show Inplace Toolbar
, f_userbtn   value space           "Show Additional Buttons in USER
, f_spinfo    value space           "Show Support Packages Info
, f_badres    value space           "Bad Resource (Connection timeout)
, ind_crop    value space           "Indicator: is list cropped?  (MAIN)
, ind_match   value space           "Indicator: is list filtered? (SESS)
, sav_crop    value space           "Saved value of IND_CROP
, intens      type i                "Intensified value
, hd1_in      type i                "Intensified value for header (MAIN)
, host_ip     like rfcdisplay-rfchost "Host IP address
, act_ind     like sy-lsind         "List index in USER
, abscol      like sy-staco value 1 "Absolute column position
, last_ln     like sy-staro         "Last line in MAIN list
, last_ln_s   like sy-staro         "Last line in SESS list
, extr_ln     like sy-staro         "Line number where EXTR_SYMB is
* lirow       like sy-staro
* lilli       like sy-lilli
, sel_bname   like sy-uname         "BNAME from selected line
, f_1stmark                         "First marker of block in MAIN
, mark1       like sy-tabix         "Marker 1              in MAIN
, mark2       like sy-tabix         "Marker 2              in MAIN
, f_1stmark_s                       "First marker of block in SESS
, mark1_s     like sy-tabix         "Marker 1              in SESS
, mark2_s     like sy-tabix         "Marker 2              in SESS
, mandt_s     like sy-mandt         "User's client         in SESS
, mandt_f     like sy-mandt         "Filter in SESS: specific client
, new_cli     like sy-mandt
, sum_usr     type i                "Number of users
, prev_sum    like sum_usr          "Previous value of number of users
, sum_act     like sum_usr          "Number of active users
, sum_lck     like sum_usr          "Number of locked users
, sum_err     like sum_usr          "Number of users with incorr. logons
, sum_ref     like sum_usr          "Number of users with reference user
, sum_ini     like sum_usr          "Number of users never logged on
, sum_miss    like sum_usr          "Number of users w/out address data
, str_usr(4)                        "String representation for SUM_USR
, str_act     like str_usr          "String representation for SUM_ACT
, langver     like adcp-nation value space
, uline_m     type i                "<- for compatibility like sy-linsz
, pop_txt     like spop-textline2
, ans                               "Answer on popup
, cnt(10)                           "Counter as string
, sav1        like dd03l-fieldname  "Saved state of sorting conditions:
, sav2        like sav1             " names of three fields
, sav3        like sav1             "   SORT BY (sav1) (sav2) (sav3)
, sav4                              " and order (ASCENDING/DESCENDING)
, s_dbcnt(10)                       "String representation for SY-DBCNT
, myname      like msxxlist-name    "My system name
, dest_rem    like myname           "Remote Application Server
, usr_dest    like myname value 'server_SID_00' "User-Defined AppServ
, platform(23)                      "OS and DB names
, kerninfo(14)                      "Kernel Info
, kern_rel    like thlines-thline   "Kernel Release
* kern_dblib     like kern_rel      "DB client library
* kern_comp_on   like kern_rel      "Compilated on: OPSYS, machine
, kern_comp_time like kern_rel      "Compilation date/time
, kern_patch     like kern_rel      "Kernel Patchlevel
* kern_patch6(6)                    "Kernel Patchlevel (first 6 chars)
, cur_app_cp(4)                     "Application Server codepage
* cur_lang(1)                       "Language
, cur_locale(40)                    "Locale, for instance, ISO-8859-5
, cur_gui_cp(4)                     "SAPGUI codepage
* cur_ap_disp_cp(4)
* cur_ap_prop_cp(4)
* cur_ap_inpu_cp(4)
* rsts_rc(6)
* rsts_errmsg(60)
, f_javagui                         "Is it SAPGUI for Java?
, f_exception                       "Is USR41 entry non GUI?
, v_obj_name  like e071-obj_name
, logsys      like t000-logsys      "Logical system
, cant_switch_lang                  "Cannot switch language
, inst_lang(8)                      "Installed languages string
, lang_len    type i
, lang_pos    like sy-fdpos
, langu       like sy-langu         "Language
* keepalive(9)                      "0 .. 999999999
, s_keepal    like tpfet-parname value 'rdisp/keepalive'
, confirmed   value space           "Confirmation on crash risk
, r_tcode     like sm04dic-tcode1
* x_tcode     like sy-tcode value 'ZUX'
, x_tcode     like sy-msgv1 value 'ZUX' "(compatible type)
, x_datum     like sy-datum         "Threshold date
, s_datum(10)                       "String representation for -"-"-
, sytitle     like sy-title         "Saved title
, f_ar                              "Search all roles or Z-roles only?

*-Command line
, cmd(24)
, new_cmd     like cmd
, old_cmd     like cmd
, syfdpos     like sy-fdpos
, sytabix     like sy-tabix
, cnt_found   like sy-dbcnt
, f_cmd_highlight value ' '         "Highlight found entry?
, f_cmd_scroll    value 'X'         "Scroll list to found entry?
, f_cmd_range     value 'X'         "Search Area Restriction ON/OFF
, f_cmd_fastfind  value ' '         "Paste and search immediately?
, f_cmd_showimpm  value ' '         "Show import-mode indicator?
, f_cmd_autoscan  value ' '         "Use full scan and mark?
, f_cmd_autocrop  value ' '         "Use auto crop?
, f_cmd_disable   value ' '         "Disable commands processing
, f_cmd_mode      value ' '         "Command mode/search mode?
, f_surnam        value ' '         "Paste: treat clipboard as surnames
, ps_impm         type i            "Import mode indicator

*-for FM POPUP_TO_DECIDE_LIST
, def_radio       like sy-lilli
, spop5titel      like spop5-titel     " 40 chars
, spop5txt1       like spop5-textline1 " 70 chars
, spop5txt2       like spop5txt1
, spop5txt3       like spop5txt1

*-System trace info
, switchbuf       like tst21        "Memory for filter sets
, f_main_off                        "Main trace is switched off
, f_auth_off                        "Authorization check is not active
, mod_user(12)                      "Changed by
, mod_time(20)                      "Changed date/time
, sw_change(33)                     "MOD_USER + MOD_TIME

* My Attributes (ThUsrInfo)
, my_terminal         like usr41-terminal
, my_tid              like usr41-termid
* my_tid              like sy-index
* hostaddr            like msxxlist-hostadr
* act_sessions        like sm04dic-counter
* max_sessions        like sm04dic-counter
* my_session          like sm04dic-counter
* my_internal_session like sm04dic-counter
* task_state          like sm04dic-counter
, my_name_first       like adrp-name_first
, my_name_last        like adrp-name_last
, v_smtp_addr         like adr6-smtp_addr
, s_email(40)
, busy_cnt            type i
, arfc_secs           like sy-index value 5

*-Value of the Profile Parameter 'auth/new_buffering'
, new_buffering       type xuflag
, slset(20)                         "Program Variant (Selection-Set)
, v_customer(10)                    "Installation number
, ui2         like uinfo2 occurs 0 with header line
, ttext       like tstct-ttext      "Transaction Text
, v_vnc       like smen_buffi-url   "Points to shared resource with VNC
, v_photos    like v_vnc            "Points to directory with photos
, btn         like smp_dyntxt       "Button on sel. screen app. toolbar
, v_icon1     like icon-id          "Icon: User works on  my   AppServ
, v_icon2     like icon-id          "Icon: User works on other AppServ

*-Program type: 1 (executable), I (include), M (module pool), etc.
, v_subc      like trdir-subc

*-Custom function modules which are desired (but not required)
, fm_personal type tt_func
, fm_th_popup type tt_func
, fm_th_pop_m type tt_func
, fm_auth_chk type tt_func
, fm_show_doc type tt_func
* fm_time_dif type tt_func
, fm_smtp_adr type tt_func
, fm_reset_pw type tt_func
, fm_to_excel type tt_func

*-Custom transactions     which are desired (but not required)
, tr_sm12     type ty_tcode value 'ZSM12' "SM12 + skip 1st screen
, tr_sm13     type ty_tcode value 'ZSM13' "SM13 for ALL users + skip
* tr_sp01     type ty_tcode value 'ZSP01' "SP01 filtered + skip 1st scr.
* tr_st01     type ty_tcode value 'ZST01' "ST01 for last 30 minutes
, tr_st22     type ty_tcode value 'ZST22' "ST22 + skip 1st screen
* tr_zlock    type ty_tcode value 'ZLOCK' "Replacement for SU10
.
*nclude <icon>.                         "SAP icons   used in lists
*nclude <symbol>.                       "SAP symbols used in lists
*nclude <line>.                         "SAP lines   used in lists
*nclude <color>.                        "SAP Standard Color Definition
include <list>.         " <list> = <icon> + <symbol> + <line> + <color>
include ztop_users.
include zrfcincl.
include slicincl.

type-pools slis.

constants:
*-Built-in SAP users
  sapstar          like sy-uname value 'SAP*'
, sapcpic          like sy-uname value 'SAPCPIC'
, ddic             like sy-uname value 'DDIC'
, tmsadm           like sy-uname value 'TMSADM'
, earlywatch       like sy-uname value 'EARLYWATCH'

*-Hard-coded Administrators
, admin_1          like sy-uname value  bc_adm1
, admin_2          like sy-uname value  bc_adm2
, admin_3          like sy-uname value  bc_adm3
, admin_4          like sy-uname value  bc_adm4
, admin_5          like sy-uname value  bc_adm5
, admin_6          like sy-uname value  bc_adm6
, admin_7          like sy-uname value  bc_adm7
, admin_8          like sy-uname value  bc_adm8
, admin_9          like sy-uname value  bc_adm9

*-Hard-coded Power users
, power_1          like sy-uname value  bc_dev1
, power_2          like sy-uname value  bc_dev2
, power_3          like sy-uname value  fi_adm1
, power_4          like sy-uname value  fi_adm2
, power_5          like sy-uname value  mm_adm1
, power_6          like sy-uname value  mm_adm2
, power_7          like sy-uname value  am_adm1
, power_8          like sy-uname value  am_adm2

*-Hard-coded activation/deactivation of additional security checks
, enable_chk1 value ' ' "Check for preset administrators
, enable_chk2 value ' ' "Check entries in table ZAUTHLST
.
data:
*-Variables for ALV
  alv_title        type sy-title
, gt_fieldcat      type slis_t_fieldcat_alv with header line
* gs_private       type slis_data_caller_exit
* gs_selfield      type slis_selfield
* g_exit(1)        type c
, g_repid          like sy-repid
, g_tabname_header type slis_tabname

*-Mass POPUP sending log
, begin of it_rec_alv occurs 0
,   client         like tmssrv-rfcclient
,   bname          like usr02-bname
,   server         like msxxlist-name
,   rc             like sy-subrc
,   iconid         like icon-id
, end   of it_rec_alv

*-SAP licenses
, custkey          type custkey_t
, instnr           type slic_inst
, expirdate        type d
, licensecount     type i value slicnolicense

, begin of license_table occurs 0
*   active
,   iconid         like icon-id
.   include structure license.
data:
  end   of license_table

, begin of licheck_entrys occurs 0.
    include structure slic_tab.
data:
  end   of licheck_entrys

*-User sessions
, begin of it_extra occurs 0.
    include structure uinfo.
data:
    iconid      like icon-id
,   iconid_info like rsmpe_txt-quickinfo
,   ip_addr(15)
,   type_txt(6)
,   stat_txt(9)
,   stat_col    type i
*   ext_time(8)
, end   of it_extra

, it_th         type standard table of uinfo with header line
, extra_cnt     like sy-tfill
, rfc_cnt       like sy-tfill
, zombie_cnt    like sy-tfill
, others_cnt    like sy-tfill
, st_extra(10)
.
constants:
*-Symbol for 'Reference user' indicator
  link_symb     like sym_filled_square value sym_filled_square
*                                            sym_right_triangle
*                                            sym_left_triangle
*                                            sym_square
*                                            sym_plus_box
*                                            sym_filled_circle
*                                            sym_bold_x
*                                            sym_document

, note_symb     like sym_note          value sym_note
, jump_symb     like sym_up_triangle   value sym_up_triangle
, frup_symb     like sym_up_triangle   value sym_up_arrow
, frdn_symb     like sym_down_triangle value sym_down_arrow

, ardn_symb     like sym_up_triangle   value sym_left_triangle
, arup_symb     like sym_down_triangle value sym_right_triangle

, iusr_icon     like icon_dummy value  icon_trend_unchanged
*                                      icon_manager
*                                      icon_hr_manager
*                                      icon_unspecified_one
*                                      icon_no_status
*                                      icon_dummy
*                                      icon_tbh

, ireg_icon     like icon_dummy value  icon_tbh
, noad_icon     like icon_dummy value  icon_presence
*                                      icon_alarm
*                                      icon_wf_workitem_cancel
*                                      icon_breakpoint
, auth_icon     like icon_dummy value  icon_layout_control
, auth_head     like icon_dummy value  auth_icon

, u010_icon     like icon_dummy value  icon_test
, u010_head     like icon_dummy value  u010_icon

, u100_icon     like icon_dummy value  icon_any_document
, u100_head     like icon_dummy value  u100_icon

* uagr_icon     like icon_dummy value  icon_activity_group
, uagr_head     like icon_dummy value  icon_activity_group

, uadr_icon     like icon_dummy value  icon_address
, uadr_head     like icon_dummy value  uadr_icon

, spoo_icon     like icon_dummy value  icon_protocol
* spoo_head     like icon_dummy value  spoo_icon

, send_icon     like icon_dummy value  icon_short_message
, send_head     like icon_dummy value  send_icon

, rdev_icon     like icon_dummy value  icon_tools
, rqas_icon     like icon_dummy value  icon_test
, rprd_icon     like icon_dummy value  icon_activity
, rusr_icon     like icon_dummy value  icon_display_more

, dalv_icon     like icon_dummy value  icon_table_settings
, file_icon     like icon_dummy value  icon_telephone_call
, mlog_icon     like icon_dummy value  icon_protocol
, dlog_icon     like icon_dummy value  icon_storno
, peri_icon     like icon_dummy value  icon_date
, lay2_icon     like icon_dummy value  icon_foreign_key
, lang_icon     like icon_dummy value  icon_rename
, selo_icon     like icon_dummy value  icon_set_state
, selr_icon     like icon_dummy value  icon_wf_link
, sela_icon     like icon_dummy value  icon_select_all
, seln_icon     like icon_dummy value  icon_deselect_all
, seli_icon     like icon_dummy value  icon_active_inactive
*                                      icon_select_block
, ctlc_icon     like icon_dummy value  icon_system_copy
, ctlv_icon     like icon_dummy value  icon_system_paste
, crop_icon     like icon_dummy value  icon_system_cut
, refr_icon     like icon_dummy value  icon_refresh
, debu_icon     like icon_dummy value  icon_debugger_step_into
, excl_icon     like icon_dummy value  icon_delete_row
, xcel_icon     like icon_dummy value  icon_xls

, su53_icon     like icon_dummy value  icon_layout_control
, wusr_icon     like icon_dummy value  icon_employee
, wagr_icon     like icon_dummy value  icon_reference_list
*                                      icon_activity_group
, dele_icon     like icon_dummy value  icon_delete
, form_icon     like icon_dummy
                  value icon_business_partner_master_d

, hist_icon     like icon_dummy value  icon_error_protocol
*                                      icon_storno
*                                      icon_overview
*                                      icon_list
*                                      icon_history
, abap_icon     like icon_dummy value  icon_layout_control
, tran_icon     like icon_dummy value  icon_execute_object
, moni_icon     like icon_dummy value  icon_biw_monitor
*                                      icon_bw_exception_monitor
*                                      icon_exception
, clis_icon     like icon_dummy value  icon_status_ok
, sm51_icon     like icon_dummy value  icon_display
, sm66_icon     like icon_dummy value  icon_justified
*                                      icon_overview
*                                      icon_trend_down
*                                      icon_oo_event
*                                      icon_parameter
*                                      icon_ranking
*                                      icon_biw_monitor
*                                      icon_rating_neutral
*                                      icon_distribute
, clea_icon     like icon_dummy value  icon_delete
, past_icon     like icon_dummy value  icon_system_paste
* impm_symb     like sym_square value
*                                      sym_down_triangle
*                                      sym_square
*                                      sym_filled_square
*                                      sym_large_square
*                                      sym_down_arrow
*                                      sym_circle
*                                      sym_diamond
, impm_icon     like icon_incoming_object
                       value icon_incoming_object
*                      value icon_trend_decreasing

************************************************************************
* Output Positions                                                     *
************************************************************************
* ps_sid        type i value  15   "SAP System Name (SID) (3)
* ps_rel        type i value  32   "SAP R/3 Release       (4)
* ps_ker        type i value  43   "Kernel Patchlevel     (5)
* ps_hst        type i value  66   "Hostname              (8)
* ps_pla        type i value  93   "Platform (OS/DB)     (10+'/'+10)
, bar_width     like sy-linsz value 22
.
data:
  ps_tb1        type i             "Tool bar at right upper corner
, ps_sm51       type i
, f_docked      value 'X'
, pack_symb     like sym_right_triangle
, spre_symb     like sym_radiobutton value sym_left_hand
, spam_symb     like sym_radiobutton value sym_right_hand
, st01_symb     like sym_check_mark
* st01_icon     like icon_dummy
, auto_symb     like sym_check_mark
* aref_symb     like sym_check_mark
, aref_icon     like icon_system_play
, filt_icon     like icon_presence
, memd_symb     like sym_right_triangle
, wide_icon     like icon_absence
, tool_symb     like sym_checkbox
, ubtn_symb     like sym_right_triangle
, extr_symb     like sym_checkbox
, erfc_symb     like sym_filled_square
, qcpy_symb     like sym_documents
, expa_symb     like sym_right_triangle
, cmdl_symb     like sym_left_triangle
* cmdl_icon     like icon_rating_positive
, mode_icon     like icon_dummy value  icon_extended_search
, choo_icon     like icon_dummy value  icon_selection
, mnew_icon     like mode_icon
, uagr_icon     like icon_dummy value  icon_activity_group
, keep_icon     like icon_hold
, chck_icon     like icon_absence
, area_icon     like icon_bw_ra_setting_inactive

, q_info_prog   like rsmpe_txt-quickinfo
, q_kern        like rsmpe_txt-quickinfo
, q_expa        like rsmpe_txt-quickinfo
, q_qcpy        like rsmpe_txt-quickinfo
, q_ardn        like rsmpe_txt-quickinfo
, q_arup        like rsmpe_txt-quickinfo
, q_auto        like rsmpe_txt-quickinfo
, q_aref        like rsmpe_txt-quickinfo
, q_cmdl        like rsmpe_txt-quickinfo
, q_impm        like rsmpe_txt-quickinfo
, q_keep        like rsmpe_txt-quickinfo
, q_chck        like rsmpe_txt-quickinfo
* q_mode        like rsmpe_txt-quickinfo
, q_area        like rsmpe_txt-quickinfo

* begin of smp_dyntext
*   text        like rsmpe-fun_txt
*   icon_id     like rsmpe-icon_id
*   icon_text   like rsmpe-icon_text
*   qinfo       like rsmpe_txt-quickinfo
* end   of smp_dyntext

*-Dynamic text for CTLV function code in MAIN status:
* dyn_ctlv      like smp_dyntext

************************************************************************
* N COLOR          INTENSIFIED  INTENSIFIED OFF  INVERSE (FOREGROUND)  *
************************************************************************
* 0 COL_BACKGROUND White        White            Black / Yellow-Pale   *
* 1 COL_HEADING    Blue         Pale Blue        Deep Blue / White     *
* 2 COL_NORMAL     Dark Gray    Light Gray       Dark Gray / White     *
* 3 COL_TOTAL      Yellow       Pale Yellow      Brown     / White     *
* 4 COL_KEY        Cyan         Pale Cyan        Pale Blue / White     *
* 5 COL_POSITIVE   Green        Pale Green       Green     / White     *
* 6 COL_NEGATIVE   Red          Pale Red         Red       / White     *
* 7 COL_GROUP      Magenta      Pale Magenta     Magenta   / White     *
************************************************************************
* Colors (these variables may be changed dynamically)                  *
************************************************************************
, c01        type i value col_normal       "BNAME
, c02        type i value col_normal       "NAME_LAST
* c03        type i value col_normal       "NAME_FIRST
, c04        type i value col_total        "TEL_NUMBER
* c05        type i value col_total        "TEL_EXTENS
, c06        type i value col_key          "FUNCTION
* c07        type i value col_key          "DEPARTMENT
* c08        type i value col_key          "BUILDING
* c09        type i value col_key          "ROOMNUMBER
* c10        type i value col_normal       "TRDAT
* c11        type i value col_normal       "LTIME
* c12        type i value col_normal       "MODBE
* c13        type i value col_normal       "MODDA
* c14        type i value col_normal       "MODTI
, foo        type i value col_heading      "Footer
, hd0        type i value col_heading      "Pre-header
, hd1        type i value col_heading      "Header fields
, pnt        type i value col_positive     "Highlighted row = {1,5,6,7}
, mrk        type i value col_group        "Marked lines
, cl_locked  type i value col_negative     "Locked users
, cl_unknown type i value col_total        "Users with unknown status
, cl_failed  type i value col_total        "Users with failed logons
, cl_extra   type i value col_positive     "Color for Extra Sessions
, cl_noaddr  type i value col_background   "Users without address data!
* cl_notused type i value col_key          "Color not used in C_BNA!!!
, cl_s_gui   type i

************************************************************************
* Columns' Margins                                                     *
************************************************************************
, l01 type i "BNAME (username)
, r01 type i "
, lm1 type i "   MARK (checkbox)
, rm1 type i "
, l02 type i "      NAME_LAST (surname)
, r02 type i "
, l03 type i "         NAME_FIRST (name)
, r03 type i "
, l04 type i "            TEL_NUMBER (job phone)
, r04 type i "
, l05 type i "               TEL_EXTENS (local phone)
, r05 type i "
, l06 type i "                  FUNCTION
, r06 type i "
, l07 type i "                     DEPARTMENT
, r07 type i "
, l08 type i "                        BUILDING
, r08 type i "
, l09 type i "                           ROOMNUMBER
, r09 type i "
, l10 type i "                              TRDAT (last logon date)
, r10 type i "
* l11 type i "                                 LTIME (last logon time)
* r11 type i "
, l12 type i "                                    MODBE (changed by)
, r12 type i "
, l13 type i "                                       MODDA (date)
, r13 type i "
, l14 type i "                                          ANAME (creator)
, r14 type i "
, l15 type i "                                             ERDAT (date)
, r15 type i "

************************************************************************
* Sorting Flags (initial sorting rules)                                *
************************************************************************
, srt_bnam value 'X'                  " Ascending by BNAME
, srt_naml value 'X'                  " Ascending by NAME_LAST
, srt_namf value 'X'                  " Ascending by NAME_FIRST
, srt_teln value 'X'                  " Ascending by TEL_NUMBER
, srt_tele value 'X'                  " Ascending by TEL_EXTENS
, srt_func value 'X'                  " Ascending by FUNCTION
, srt_depa value 'X'                  " Ascending by DEPARTMENT
, srt_buil value 'X'                  " Ascending by BUILDING
, srt_room value 'X'                  " Ascending by ROOMNUMBER
, srt_trda value ' '                  "Descending by TRDAT
, srt_modb value 'X'                  " Ascending by MODBE
, srt_modd value ' '                  "Descending by MODDA
, srt_anam value 'X'                  " Ascending by ANAME
, srt_erda value ' '                  "Descending by ERDAT

************************************************************************
* Authorization flags                                                  *
************************************************************************
* auth_nadm                           "Network Administration
, auth_padm                           "Process Administration
* auth_audd                           "Display Audit  Log
* auth_sm21                           "Display System Log
, auth_sm02                           "Create  System Messages
, auth_st0r                           "Display System Traces
.
*-Note: auth. field ST0R is used here to hide IP-addresses

************************************************************************
* Internal Tables                                                      *
************************************************************************
types:
  begin of ty_it
,   mandt      like usr02-mandt       "Client
,   bname      like usr02-bname       "User logon name
,   ustyp      like usr02-ustyp       "User's type: A, B, C, S, L
,   class      like usgrp_user-usergroup
,   locnt      like usr02-locnt       "Failed logons
,   uflag      like usr02-uflag       "Locking flag
,   aname      like usr02-aname       "Who has created user account
,   erdat      like usr02-erdat       "Date of creation
,   trdat      like usr02-trdat       "Last logon date
,   ltime      like usr02-ltime       "Last logon time
,   persnumber like usr21-persnumber  "Person ID
,   addrnumber like usr21-addrnumber  "Address ID
,   modda      like usr04-modda       "Date of modification
,   modti      like usr04-modti       "Time of modification
,   modbe      like usr04-modbe       "Last modifier
*   title      like adrp-title        "User's title
,   name_first like adrp-name_first   "User's first name
,   name_last  like adrp-name_last    "User's surname
*   sex        like adrp-sex          "User's sex
,   department like adcp-department   "Department
,   function   like adcp-function     "User's description
,   building   like adcp-building     "Building
*   floor      like adcp-floor        "Floor
,   roomnumber like adcp-roomnumber   "Room
,   tel_number like adcp-tel_number   "Phone number
,   tel_numdis like adcp-tel_number   "Phone number for display
,   tel_extens like adcp-tel_extens   "Local phone number
,   refuser    like usrefus-refuser   "Reference to other user
*   filter     type c                 "Filtration tag
,   mark       type c                 "Selection tag
,   noaddr     type c                 "Selection tag: Address missing
*   nomail     type c                 "Selection tag: E-mail missing
*   nophone    type c                 "Selection tag: Phone missing
,   online     type c                 "User currently online
,   iconid     type icon-id
*   iconname   type icon-name
,   c_bna      type i                 "Color for BNAME
,   c_ana      type i                 "Color for ANAME
,   c_erd      type i                 "Color for ERDAT
,   c_trd      type i                 "Color for TRDAT
,   c_lti      type i                 "Color for LTIME
,   c_mda      type i                 "Color for MODDA
,   c_mti      type i                 "Color for MODTI
,   c_mbe      type i                 "Color for MODBE
,   c_nfi      type i                 "Color for NAME_FIRST
,   c_nla      type i                 "Color for NAME_LAST
,   c_dep      type i                 "Color for DEPARTMENT
,   c_fun      type i                 "Color for FUNCTION
,   c_bui      type i                 "Color for BUILDING
,   c_roo      type i                 "Color for ROOMNUMBER
,   c_tnu      type i                 "Color for TEL_NUMBER
,   c_tex      type i                 "Color for TEL_EXTENSION
, end   of ty_it

, begin of ty_it41s.
    include structure usr41.
  types:
    persnumber like usr21-persnumber  "User ID
,   name_first like adrp-name_first   "User's first name
,   name_last  like adrp-name_last    "User's surname
,   time       like uinfo2-time       "Time of latest dialog step
,   diff       like sy-uzeit          "Wastetime = current - latest
*   include structure ublks.
,   tcode      like ublks-tcode
,   key        like ublks-key
,   page       like ublks-page
,   roll       like ublks-roll
,   tid        like ublks-tid
,   memsum     like ublks-memsum
,   privsum    like ublks-privsum
,   mark
, end   of ty_it41s

, begin of ty_it_rec
,   client     type symandt
,   bname      type xubname
,   server     type xuserver
*---for BW, ERP2005, SSM: type SUBRC2. For 46C: type SUBRC
,   rc         type subrc
, end   of ty_it_rec

, ty_user      like sy-uname
.
field-symbols:
  <fs>         type ty_it
, <fs2>        type ty_it41s  "<-does not work with GET CURSOR FIELD
, <fs3>        type uinfo2
, <fs4>        type spam_cvers
.
data:
  st_it        type ty_it
, st_it41s     type ty_it41s
, st_it_rec    type ty_it_rec

*-Main data table
, begin of it       occurs occ_val.
    include structure st_it.
data:
  end   of it

*-Table with phone numbers (to upload from PC)
, begin of it_phone occurs occ_val
,   bname      like usr02-bname       "User
,   tel_number like adcp-tel_number   "Phone number
,   tel_extens like adcp-tel_extens   "Local phone number
,   comment(40)                       "Comment
, end   of it_phone

*-Activity table (online, offline)
, begin of it41     occurs occ_val
,   bname      like sy-uname          "User logon name
,   server     like usr41-server      "Application Server
, end   of it41

*-Table with users' sessions
, begin of it41s    occurs occ_val.
    include structure st_it41s.
data:
  end   of it41s

, begin of usr_btabl occurs 10.
    include structure ublks.
data:
  end   of usr_btabl

*-Table for mass POPUP
* it_rec type standard table of zpopup_receivers with header line
, begin of it_rec occurs occ_val.
    include structure st_it_rec.
data:
  end   of it_rec

*-Table for FM POPUP_TO_DECIDE_LIST
, it_spopli     type standard table of spopli  with header line

*-Table to transferring users' IDs
, usrlist       type standard table of ususers with header line

*-Table to transferring users' surnames
, begin of surnames occurs 0
,   name_last   like adrp-name_last
, end   of surnames

, sum_act_s     type i         "Number of user sessions
, str_act_s(4)                 "String representation for -"-"-
, col_diff      type i         "Color for wastetime
, rc  like sy-subrc            "Return code
, tab like dd03l-tabname       "table name: not used in this report
, fld like dd03l-fieldname
                value  c_fld   "field name for initial sorting
, nav like dd03l-fieldname
, sort_flg      value 'X'      "space - descending, 'X' - ascending
, waste_flg     value 'X'      "space - abs. time, 'X' - waste time
, f_th_all                     "Show all THUSERINFO entries (EXPERT)
.
types:
*-Table type for import messages after BDC call
  tt_errtab type standard table of bdcmsgcoll
.
data:
    msg_log type standard table of rsuvm_msg with header line
, x_msg_log type standard table of rsuvm_msg with header line
, it_sp     type standard table of spam_cvers
.
data:
  it_usrtab type sorted table of ty_user with unique key table_line
,     begin of extab1  occurs 9           "Forbidden function codes 1
,       fcode like rsmpe-func
,     end   of extab1

,     begin of extab2  occurs 4           "Forbidden function codes 2
,       fcode like rsmpe-func
,     end   of extab2

,     begin of extab3  occurs 8           "Forbidden function codes 3
,       fcode like rsmpe-func
,     end   of extab3

,     begin of fields  occurs 10.
        include structure sval.
data: end   of fields

,     username(82)
,     expert
,     phone_flg

,     begin of t_msglst occurs 0
,       msg like wptotlicer-com_error
,     end   of t_msglst
.
data: begin of t_fld    occurs 0.
        include structure help_value.
data: end   of t_fld.

data: begin of t_val    occurs 1
,       value(128)
,     end   of t_val.

data: begin of t_srv    occurs 0.
        include structure msxxlist.
data: end   of t_srv.

*-Support for ListBox
* type-pools: vrm.
* data:
*   it_val type vrm_values
* , w_line like line of it_val
* .

* HTML pane
types
  ty_html_color(6) type c
.
constants:
*-Background colors for SAPGUI Color Themes
* c_complementary type ty_html_color value '95B2C3' "Standard
* c_new_millenium type ty_html_color value 'BCBCBC' "Gray
* c_summer_rain   type ty_html_color value 'A0ABB2' "Dark gray
* c_grass         type ty_html_color value 'AACB88' "Green
* c_ocean_teal    type ty_html_color value '86BABA' "Dark green
* c_ocean_teal_b  type ty_html_color value 'BAEFEF' "Dark green
* c_peach         type ty_html_color value 'EAD3AF' "Beige
* c_rose          type ty_html_color value 'E2B1BE' "Rose

*-Custom background colors
* c_white_smoke   type ty_html_color value 'EAEAE8' "White
* c_milk          type ty_html_color value 'FFFFEF' "White
* c_quickinfo     type ty_html_color value 'FFFFDF' "Yellow
* c_yellow_butter type ty_html_color value 'FEFEB8' "Yellow
* c_desert        type ty_html_color value 'DDDDAA' "Yellow
* c_pale_green    type ty_html_color value 'AFCFAF' "Green
* c_pale_green_b  type ty_html_color value 'CDE8BF' "Green
* c_cyan          type ty_html_color value '01D0FF' "Cyan
* c_zinc          type ty_html_color value 'DDEFEF' "Cyan
* c_blue_loam     type ty_html_color value 'ACDEDE' "Cyan
  c_azure_blue    type ty_html_color value '3399FF' "Light blue
* c_blue_violet   type ty_html_color value '7C97E8' "Violet
.
data:
*-Docked Containter
  dc              type ref to cl_gui_docking_container

*-Dynamic Document
, dd              type ref to cl_dd_document
, str_html        type string

*-Stores visibility value of the control
, f_visible   value '0'        " '0' - invisible, '1' - visible
, f_altpict                    "Use alternative user's photo
, f_altbkgr                    "Use alternative background color
, f_resize    value 'X'        "Use original or fixed size of a photo
, bg_color        type ty_html_color value c_azure_blue

*-Control initialized? [~Needed for dd->display_document up to 46C SP52]
, ctrl_init

*-Last user displayed in HTML pane
, last_html_bname like usr02-bname
.
************************************************************************
* Macros                                                               *
************************************************************************
define sscr_chkbox.
  parameters &1 as checkbox default &2.
  selection-screen comment 33(60) &3 modif id blu.
end-of-definition. "SSCR_CHKBOX
*-----------------------------------------------------------------------
define sscr_comment.
  selection-screen begin of line.
    selection-screen comment 2(60) &1 modif id blu.
  selection-screen end   of line.
end-of-definition. "SSCR_COMMENT
*-----------------------------------------------------------------------
define sscr_comment_65. " (54 max with 'no intervals' addition)
  selection-screen begin of line.
    selection-screen comment 2(65) &1 modif id blu.
  selection-screen end   of line.
end-of-definition. "SSCR_COMMENT_65
*-----------------------------------------------------------------------
define sscr_icon.
  parameter &1 like icon-id.
  selection-screen comment 43(30) &2 modif id blu.
end-of-definition. "SSCR_ICON
*-----------------------------------------------------------------------
define sscrtab.
  selection-screen tab (25) &1 user-command &2 default screen &3.
end-of-definition. "SSCRTAB
*-----------------------------------------------------------------------
define fill_def_icon.
  move &1 to &3.
  concatenate &3 &2 into &3 separated by space.
end-of-definition. "FILL_DEF_ICON
*-----------------------------------------------------------------------
define fill_btn.
  btn-text      =  &1.               "Fuction text (menu)
  btn-icon_id   =  &2.               "Icon ID
  btn-icon_text =  &3.               "Icon text
  btn-quickinfo =  &4.               "Quick info
  btn-path      =  ' '.              "Direct path (one char)
  move btn to &5.
end-of-definition. "FILL_BTN
*-----------------------------------------------------------------------
define app1.
  move &1 to extab1-fcode. append extab1.
end-of-definition. "APP1
*-----------------------------------------------------------------------
define app2.
  move &1 to extab2-fcode. append extab2.
end-of-definition. "APP2
*-----------------------------------------------------------------------
define app3.
  move &1 to extab3-fcode. append extab3.
end-of-definition. "APP3
*-----------------------------------------------------------------------
define app_log.
  msg_log-msgty = 'I'.
  msg_log-msgid = &1.
  msg_log-msgno = &2.
  msg_log-msgv1 = &3.
  msg_log-msgv2 = &4.
  msg_log-msgv3 = &5.
  msg_log-msgv4 = &6.
  append msg_log.
end-of-definition. "APP_LOG
*-----------------------------------------------------------------------
define app_log_ds_1.
  app_log    'DS' '017' &1   ' '  ' '  ' '.
end-of-definition. "APP_LOG_DS_1
*-----------------------------------------------------------------------
define app_log_00.
  app_log    '00'  &1   &2   &3   &4   &5 .
end-of-definition. "APP_LOG_00
*-----------------------------------------------------------------------
define app_log_00_0.
  app_log_00       &1   ' '  ' '  ' '  ' '.
end-of-definition. "APP_LOG_00_0
*-----------------------------------------------------------------------
define app_log_00_1.
  app_log_00       &1   &2   ' '  ' '  ' '.
end-of-definition. "APP_LOG_00_1
*-----------------------------------------------------------------------
define app_log_z2.
  app_log    'Z2'  &1   &2   &3   &4   &5 .
end-of-definition. "APP_LOG_Z2
*-----------------------------------------------------------------------
define app_log_z2_0.
  app_log_z2       &1   ' '  ' '  ' '  ' '.
end-of-definition. "APP_LOG_Z2_0
*-----------------------------------------------------------------------
define app_log_z2_1.
  app_log_z2       &1   &2   ' '  ' '  ' '.
end-of-definition. "APP_LOG_Z2_1
*-----------------------------------------------------------------------
define app_log_z2_2.
  app_log_z2       &1   &2   &3   ' '  ' '.
end-of-definition. "APP_LOG_Z2_2
*-----------------------------------------------------------------------
define app_log_z2_3.
  app_log_z2       &1   &2   &3   &4   ' '.
end-of-definition. "APP_LOG_Z2_3
*-----------------------------------------------------------------------
define app_log_z2_008.
  app_log_z2_1    '008' &1.
end-of-definition. "APP_LOG_Z2_008
*-----------------------------------------------------------------------
define app_avoid.
  avoid-low       = &1.
  avoid-sign      = 'I'.
  avoid-option    = 'EQ'.
  append avoid.
end-of-definition. "APP_AVOID
*-----------------------------------------------------------------------
define app_filter1.
  clear so_bname.
  so_bname-low    = &1.
  so_bname-sign   = 'E'.
  so_bname-option = 'EQ'.
  append so_bname.
end-of-definition. "APP_FILTER1
*-----------------------------------------------------------------------
define app_filter2.
  clear so_ustyp.
  so_ustyp-low    = &1.
  so_ustyp-sign   = 'I'.
  so_ustyp-option = 'EQ'.
  append so_ustyp.
end-of-definition. "APP_FILTER2
*-----------------------------------------------------------------------
define app_spopli.
  it_spopli-selflag   = &1.
  it_spopli-varoption = &2.
  it_spopli-inactive  = &3.
  append it_spopli.
end-of-definition. "APP_SPOPLI
*-----------------------------------------------------------------------
define app_t_fld_s.
  t_fld-tabname    = &1.
  t_fld-fieldname  = &2.
  t_fld-selectflag = 'X'.
  append t_fld.
end-of-definition. "APP_T_FLD_S
*-----------------------------------------------------------------------
define app_t_fld.
  t_fld-tabname    = &1.
  t_fld-fieldname  = &2.
  t_fld-selectflag = ' '.
  append t_fld.
end-of-definition. "APP_T_FLD
*-----------------------------------------------------------------------
define a_flds.
  fields-tabname   = &1.
  fields-fieldname = &2.
  fields-fieldtext = &3.
  fields-value     = &4.
  append fields.
end-of-definition. "A_FLDS
*-----------------------------------------------------------------------
define app_t_msglst.
  t_msglst-msg = &1.
  append t_msglst.
end-of-definition. "APP_T_MSGLST
*-----------------------------------------------------------------------
define fill_t_val.
  field-symbols <f> type any.

  free t_val.
  loop at &1.
    do.
      assign component sy-index of structure &1 to <f>.
      if sy-subrc <> 0. exit. endif.
      append <f> to t_val.
    enddo.
  endloop.
end-of-definition. "FILL_T_VAL
*-----------------------------------------------------------------------
define repl.
  move &1 to &3.
  replace amp with &2 into &3.
  condense &3.
end-of-definition. "REPL
*-----------------------------------------------------------------------
define repl2.
  replace &1 with &2 into &3. condense &3.
end-of-definition. "REPL2
*-----------------------------------------------------------------------
define set_titlebar_001.
  set titlebar '001' with sel_bname sy-sysid.
end-of-definition. "SET_TITLEBAR_001
*-----------------------------------------------------------------------
define set_titlebar_002.
  set titlebar '002' with sel_bname sy-sysid sy-mandt.
end-of-definition. "SET_TITLEBAR_002
*-----------------------------------------------------------------------
define sessions_toggle_flag.
  perform toggle_flag changing &1.
  perform refresh_list_s.
end-of-definition. "SESSIONS_TOGGLE_FLAG
*-----------------------------------------------------------------------
define check_sel_bname.
  if sel_bname is initial.
    app_log_00_0 '301'.
*--'Position the cursor on a line in the list'
    message e301(00).
*   message e001.                  "Place cursor at correct line
    exit.
  endif.
end-of-definition. "CHECK_SEL_BNAME
*-----------------------------------------------------------------------
define get_and_check_sel_bname.
  perform get_bname.
  check_sel_bname.
end-of-definition. "GET_AND_CHECK_SEL_BNAME
*-----------------------------------------------------------------------
define is_tab_exists.
  select count( * ) from dd02l
                    where tabname  =  &1
                      and as4local = 'A'
                      and as4vers  = '0000'
                          .
end-of-definition. "IS_TAB_EXISTS
*-----------------------------------------------------------------------
define check_mark_exists.
  read table it with key mark = 'X'.
end-of-definition. "CHECK_MARK_EXISTS
*-----------------------------------------------------------------------
define plunger.
  message i030 with 'Not yet implemented. Coming soon...'. "#EC NOTEXT
  exit.
end-of-definition. "PLUNGER
*-----------------------------------------------------------------------
define deny_because_of_arfc.
  app_log_z2_0 '098'.
*'Cannot continue: ARFC call still active'
  message s098.
  exit.
end-of-definition. "DENY_BECAUSE_OF_ARFC
*-----------------------------------------------------------------------
define check_arfc.
*-Check for active ARFC calls
  if not busy_cnt is initial.
*   pop_txt = 'Wait up to $ seconds or cancel?'.
*   move arfc_secs to st_secs.
*   replace '$' with st_secs into pop_txt. condense pop_txt.
*   confirm_step 'N'
*                'ARFC call still active'(792)
*                 pop_txt
*                'ARFC call still active'(792)
*                 .
*   if ans <> 'J'. exit. endif.
*   wait until busy_cnt eq 0 up to arfc_secs seconds.
*   clear: p_aref, busy_cnt.
    deny_because_of_arfc.
  endif.
end-of-definition. "CHECK_ARFC
*-----------------------------------------------------------------------
define show_details.
  if &2 = sy-mandt.
    perform popup_user_display_addr using &1.
  else.
    call function 'SUSR_SHOW_USER_DETAILS'
         exporting
           bname = &1
           mandt = &2
           .
  endif.
end-of-definition. "SHOW_DETAILS
*-----------------------------------------------------------------------
define set_fcode_ex.
  call function 'SAPGUI_SET_FUNCTIONCODE'
       exporting
         functioncode = &1
       exceptions
         others       = &2
         .
end-of-definition. "SET_FCODE_EX
*-----------------------------------------------------------------------
define set_fcode.
  set_fcode_ex &1 0. " <-- Mask all exceptions here
end-of-definition. "SET_FCODE
*-----------------------------------------------------------------------
define confirm_step.
  clear ans.
  call function 'POPUP_TO_CONFIRM_STEP'
       exporting
         defaultoption  = &1
         textline1      = &2
         textline2      = &3
         titel          = &4
         start_column   = 25
         start_row      =  5
*        cancel_display =  space
       importing
         answer         =  ans
         .
end-of-definition. "CONFIRM_STEP
*-----------------------------------------------------------------------
define release_check.
  if sy-saprl ge c_saprl.
    concatenate 'This feature works unstable on SAP Release'(929)
                 sy-saprl
           into  pop_txt
                 separated by space
                 .
    condense pop_txt.

    confirm_step 'N'
                  pop_txt
                 'Continue anyway?'(928)
                 'Echo ON/OFF confirmation'(927)
                  .
    if ans <> 'J'. exit. endif.
  endif.
end-of-definition. "RELEASE_CHECK
*-----------------------------------------------------------------------
define keepalive_check.
  if not p_chkpar is initial and confirmed is initial.
*---Read value everytime to catch dynamic switches of 'rdisp/keepalive'.
    perform get_keepalive changing keepalive.
    if keepalive <> 0.
      perform crash_warning using keepalive changing ans.
      if ans = '1'. confirmed = 'X'. endif.
*-----If not confirmed then break current procedure
*     (Keep in mind that this is MACRO!!!)
      if confirmed is initial. exit. endif.
*-----Continue with current procedure
    endif.
  endif.
end-of-definition. "KEEPALIVE_CHECK
*-----------------------------------------------------------------------
define is_executable.
*-Check for active ARFC calls
  check_arfc.

*-Check program existence
  perform check_program_existence using &1.
  if sy-subrc <> 0.
    app_log_ds_1 &1.
*--'Program & does not exist'
    message e017(ds) with &1.
    exit.
  endif.

*-Check program type (moved to CHECK_PROGRAM_EXISTENCE)
* select single subc from trdir
*                    into (v_subc)
*                    where name = &1
*                          .
  if v_subc <> '1'. "<-- if it isn't executable program
*   app_log 'ED' '811' v_repid v_subc space space.
*--'& is not a report program (type '&')'
*   message e811(ed) with v_repid v_subc.
    app_log 'EU' '482' &1 v_subc space space.
*--'Program &1 is not executable (wrong program type &2)'
    message e482(eu) with &1 v_subc.
    exit.
  endif.
end-of-definition. "IS_EXECUTABLE
*-----------------------------------------------------------------------
define navigation_impossible.
* app_log 'WD' '498' space space space space.
*'Navigation is not possible'
  message s498(wd).
  exit.
end-of-definition. "NAVIGATION_IMPOSSIBLE
*-----------------------------------------------------------------------
define select_valid_line.
*'Place cursor on a valid line'
* message s898(s1). "<- Message hasn't translation in Russian
  app_log 'SR' '015' space space space space.
*'Select a valid line'
  message s015(sr).
  exit.
end-of-definition. "SELECT_VALID_LINE
*-----------------------------------------------------------------------
define select_valid_field.
*-Restore default sorting
  fld = c_fld.
  app_log 'TD' '303' space space space space.
*'Position the cursor on a table field'
  message w303(td).
* exit.
end-of-definition. "SELECT_VALID_FIELD
*-----------------------------------------------------------------------
define s_and_p.
  perform sort_and_print using &1 &2 &3 changing &4.
end-of-definition. "S_AND_P
*-----------------------------------------------------------------------
define authdet.
  perform auth_check using &1 changing &2.
end-of-definition. "AUTHDET
*-----------------------------------------------------------------------
define cls.
  refresh &1. clear &1.
end-of-definition. "CLS
*-----------------------------------------------------------------------
define check_wrong_fields.
  if sy-subrc = 1.
    app_log_z2_008 text-500.
*--'Error: &1'
    message e008 with 'incorrect fields'(500).
*   exit. " Not need for message type 'E'
  endif.
end-of-definition. "CHECK_WRONG_FIELDS
*-----------------------------------------------------------------------
define r_flds.
  read table fields index &1. &2 = fields-value.
end-of-definition. "R_FLDS
*-----------------------------------------------------------------------
define fm_det.
  perform check_function  using &1 changing &2.
end-of-definition. "FM_DET
*-----------------------------------------------------------------------
define tr_det.
  perform set_transaction using &1 changing &2.
end-of-definition. "TR_DET
*-----------------------------------------------------------------------
define r_names.
  move:
    it-name_first to &1
  , it-name_last  to &2
  .
end-of-definition. "R_NAMES
*-----------------------------------------------------------------------
define get_param.
  call 'C_SAPGPARAM'
    id 'NAME'  field &1
    id 'VALUE' field &2
    .
end-of-definition. "GET_PARAM
*-----------------------------------------------------------------------
define check_icon.
  move &1 to &3.         "Default -> Assigned
  if not &2 is initial.  "Specified <> space?
    select count( * ) from icon where id = &2.
    if sy-subrc = 0. move &2 to &3. endif.
  endif.
end-of-definition. "CHECK_ICON
*-----------------------------------------------------------------------
define adapt_client.
  data len type i.
  if not &1 is initial.
    condense &1.
    do.
      len = strlen( &1 ).
      if len > 2. exit. endif.
      concatenate '0' &1 into &1.
    enddo.

    if not &1 co '0123456789'.
      app_log_z2_1 '030' text-883.
      message w030 with 'Client must have a numeric value'(883).
      exit.
    endif.
  else. exit. endif.
end-of-definition. "ADAPT_CLIENT
*-----------------------------------------------------------------------
*define get_current_date.
*  select * from t247
*           where spras = langu
*             and mnr   = sy-datum+4(2)
*                 .
*  endselect.
*  if sy-subrc <> 0.
*    write sy-datum to c_dat using edit mask t_mask.
*  else.
*    concatenate sy-datum+6(2) t247-ltx(3) sy-datum+0(4)
*           into c_dat
*                separated by '-'
*                .
*  endif.
*  concatenate '@CZ@' c_dat into c_dat.
*end-of-definition. "GET_CURRENT_DATE
*-----------------------------------------------------------------------
define save_titlebar.
  sytitle = sy-title.
end-of-definition. "SAVE_TITLEBAR
*-----------------------------------------------------------------------
define restore_titlebar.
  sy-title = sytitle.
end-of-definition. "RESTORE_TITLEBAR
*-----------------------------------------------------------------------
define progress_ind.
  call function 'SAPGUI_PROGRESS_INDICATOR' exporting text = &1.
end-of-definition. "PROGRESS_IND

************************************************************************
* Selection Screen                                                     *
************************************************************************
selection-screen function key 1.             "Button #1 - Hint
selection-screen function key 2.             "Button #2 - DEV
selection-screen function key 3.             "Button #3 - QAS
selection-screen function key 4.             "Button #4 - PRD

*-Welcome message
selection-screen begin of block welcome.
* selection-screen comment /64(15) c_dat.  "odif id blu.
  selection-screen skip.
*-Output comment from position 1
  selection-screen comment /1(80) salut    modif id blu.
  selection-screen comment /3(61) text-017 modif id blu.
*-select desired options, then press the "Execute" or <F8> key

*-Execute
  selection-screen pushbutton 65(13) b_onli user-command onli.
selection-screen end   of block welcome.

selection-screen skip.                       "Skip 1 line on the screen

*-Ranges for user's name, type
selection-screen begin of screen 101 as subscreen.
  selection-screen begin of line.            "Output at one line
*---Users from the
    selection-screen comment  1(15) text-007."Alternate way for comment
    selection-screen position 19.            "Where put combobox
*---Mandant
    parameter p_mandt like t000-mandt
*             as listbox visible length 5
              default sy-mandt obligatory
              .
*---client, system, installation no.
    selection-screen comment 27(22) c_mansys.
    selection-screen comment 51(30) c_cust modif id blu.
  selection-screen end   of line.

  selection-screen skip.
*-User name
  select-options
    so_bname for usr02-bname " matchcode object user_addr
  .
  selection-screen begin of line.
*---Import users from clipboard (REPLACE mode)
    selection-screen pushbutton 35(09) b_impr user-command impr.
*---Clear users
    selection-screen pushbutton 45(04) b_nous user-command nous.
*---Import users from clipboard (ADD mode)
    selection-screen pushbutton 60(12) b_impa user-command impa.
  selection-screen end   of line.

  select-options
*---User type
    so_ustyp for usr02-ustyp " default 'A'
  .
  selection-screen begin of line.
*---Delete all filters
    selection-screen pushbutton 35(12) b_fdel user-command fdel.
*---Restore predefined filter
    selection-screen pushbutton 60(12) b_fset user-command fset.
  selection-screen end   of line.
  select-options:
*---Group for authorization
    so_class for usr02-class
*---User group (general)
  , so_group for usr02-class
  .
*  sscr_comment c_typ1.
*  sscr_comment c_typ2.
*  sscr_comment c_typ3.
*  sscr_comment c_typ4.
*  sscr_comment c_typ5.

  selection-screen skip.
*-Maximum number of hits (unlimited by default)
  parameter p_rows like rseumod-tbmaxsel default 0.
  selection-screen skip.

*-Filter for SM50, SM04, SM12
  sscr_chkbox p_usfilt 'X' text-968.
*-@4G@Filter output on specified user

*-Filtered active sessions
  sscr_chkbox p_match  ' ' text-085.
*-@4G@Show selected users only

*-Use as default tabstip
* sscr_chkbox p_deftab 'X' text-925.
*-'@LX@Open this tabstrip when the selection screen is called'

* selection-screen skip.
*-Documentation hint
* sscr_comment c_doc.
selection-screen end   of screen 101.

selection-screen begin of screen 103 as subscreen.
*-Check value 'rdisp/keepalive'
* sscr_chkbox p_chkpar 'X' text-106.
*-@FC@Value for timer of unused TCP/IP-connections

*-Check for Auth. Failure
  sscr_chkbox p_fail   'X' text-818.
*-@38@Search an entry in tab. USR07 for a user

*-Check for trace status
  sscr_chkbox p_swst01 'X' text-967.
*-@38@Check for current status of ST01 switches

*-Look for special connections
  sscr_chkbox p_extra  'X' text-990.
*-@BW@Count RFC connections, Plugins and others

*-Back to first page
  sscr_chkbox p_return 'X' text-819.
*-@2Y@At new selection - scroll list to first page

*-Preset start time for STAT
  sscr_chkbox p_stat2h 'X' text-824.
*-@BH@Propose value (Now - 2 hours) as STAT's start time

*-Refresh-on-Return
  sscr_chkbox p_refr   'X' text-804.
*-@42@Refresh list on return from called transaction

*-Auto-jump to SESS
  sscr_chkbox p_jump   ' ' text-805.
*-@43@Jump directly to active user list

*-Create empty E-mail
  sscr_chkbox p_nofill ' ' text-813.
*-@DZ@Do not fill E-mail header and body

*-Transactions in new mode
  sscr_chkbox p_newmod ' ' text-816.
*-@32@Start transactions in new mode

*-Copy username when doubleclick on NAME_LAST?
  sscr_chkbox p_cpynam ' ' text-389.
*-@4O@Copy username when doubleclick on NAME_LAST

  selection-screen uline.
  selection-screen skip.
*-Upload phones from PC-file
  parameter p_upload
    as checkbox
*   modif id adm
    default ' '
    user-command uplo
    .
  selection-screen comment 33(60) text-999 modif id adm.
*-@KM@Upload phones from file on network resource
  parameter
*---Path to flat file with phone numbers
    p_phones like smen_buffi-url
  .
selection-screen end   of screen 103.

selection-screen begin of screen 102 as subscreen.
*-Layout colors
  parameters:
    p_prn radiobutton group radi user-command prn
  , p_scr radiobutton group radi default 'X'
  .
  selection-screen uline.
*-Is command line visible?
  sscr_chkbox p_cmd    ' ' text-388.
*-@K2@Display command line

*-Pointer
  sscr_chkbox p_point  'X' text-010.
*-@BF@Highlight own account

*-Smart scrolling
  sscr_chkbox p_scroll 'X' text-031.
*-@3V@Key field is always on the screen

*-Single click
  sscr_chkbox p_hot    'X' text-033.
*-@MH@Single click instead of double when sorting list

*-Contrast scheme
  sscr_chkbox p_intens ' ' text-030.
*-@44@Use high intensity colors

*-Hide IP-addresses
  sscr_chkbox p_no_ip  ' ' text-084.
*-@5A@Show terminal name without IP-address

*-User's context
  sscr_chkbox p_detail ' ' text-815.
*-@3R@Show memory details

*-System-wide sessions or client specific (when P_MATCH = 'X')
  parameter p_wide   default 'X' no-display.
*-Wide/short format for TEL_NUMBER
  parameter p_expand default ' ' no-display.
  selection-screen uline.

*-Autorefresh
  parameter p_aref   default ' ' no-display.

*-Warning limit = 30 days old     " ccparparm-counter
* parameter p_period like tpri_par-parlistlen default 30.
  parameter p_period like ccparparm-counter   default 30.

  sscr_icon p_icon1 c_icon1."Icon: User works on  my   AppServ
  sscr_icon p_icon2 c_icon2."Icon: User works on other AppServ
selection-screen end   of screen 102.

selection-screen begin of screen 104 as subscreen.
  selection-screen begin of block b_nls.
    parameter p_appcp like tcp00-cpcodepage modif id nls.
    selection-screen comment 42(38) c_appcp modif id nls.

    parameter p_guicp like tcp00-cpcodepage modif id nls.
    selection-screen comment 42(38) c_guicp modif id nls.
    parameter p_locale(40)                  modif id nls.
    selection-screen skip.
  selection-screen end   of block b_nls.

  selection-screen begin of block b_bls.
*---Show information about code pages (AppServ, SAPGUI) and NLS locale
    selection-screen pushbutton  3(55) b_snls
                     user-command snls modif id bls.
    selection-screen skip.
  selection-screen end   of block b_bls.

  sscr_comment c_doc1.
  sscr_comment c_doc2.
  sscr_comment c_doc3.
  sscr_comment c_doc4.
  sscr_comment c_doc5.

  selection-screen begin of line.
*------------------------------'Application Server'
    selection-screen comment  2(18) text-143 modif id blu.
    selection-screen position 21.
    parameter p_host like sy-host modif id off.
*------------------------------------'Time'
    selection-screen comment  36(6) text-032 modif id blu.
    selection-screen position 45.
    parameter p_time(8) modif id off.
*---Refresh time display
    selection-screen pushbutton 55(4) b_time user-command time.
  selection-screen end   of line.

  selection-screen skip.

*-Expert mode
  selection-screen begin of block expmode
                   with frame
                   title text-061 "Authentification
                   no intervals   "Short variant
                   .
*---Password
    selection-screen begin of line.
      selection-screen comment 30(15) c_pwd.
      selection-screen position 46.
      parameter p_pwd(8) modif id exp.
    selection-screen end   of line.
  selection-screen end   of block expmode.
selection-screen end   of screen 104.

selection-screen begin of screen 105 as subscreen.
  selection-screen begin of block b_ver
                   with frame
                   title text-151 "Version information
                   .
    selection-screen begin of line.
      selection-screen comment  25(40) c_titl          modif id blu.
      parameter p_title like trdirt-text no-display    modif id off.
    selection-screen end   of line.

    selection-screen begin of line.
      selection-screen comment  1(11) c_prog           modif id blu.
      parameter p_repid like sy-repid default sy-repid modif id off.
    selection-screen end   of line.

    selection-screen begin of line.
      selection-screen comment  1(11) c_crea           modif id blu.
      parameters:
        p_cnam  like trdir-cnam                        modif id off
      , p_cdat  like trdir-cdat                        modif id off
      .
      selection-screen comment 39(9)  c_srcs           modif id blu.
      parameter p_srcsy like tadir-srcsystem           modif id off.
      selection-screen comment 62(11) c_lang           modif id blu.
      parameter p_lang  like tadir-masterlang          modif id off.
    selection-screen end   of line.

    selection-screen begin of line.
      selection-screen comment  1(11) c_chan           modif id blu.
      parameters:
        p_unam  like trdir-unam                        modif id off
      , p_udat  like trdir-udat                        modif id off
      .
      selection-screen comment 39(9)  c_vern           modif id blu.
      parameter p_vern  like trdir-vern                modif id off.
    selection-screen end   of line.

    selection-screen begin of line.
      selection-screen comment  1(24) c_sscr           modif id blu.
      parameter p_sdat  like trdir-sdate               modif id off.
      selection-screen comment 39(9)  c_stim           modif id blu.
      parameter p_stim(8)                              modif id off.
    selection-screen end   of line.
  selection-screen end   of block b_ver.

  selection-screen skip.

*-Leave system
  selection-screen begin of block sysexit
                   with frame
                   title text-075 "Leave system
*                  no intervals   "Short variant
                   .
    sscr_comment_65 c_doc6.
    sscr_comment_65 c_doc7.

    selection-screen begin of line.
*-----Quit! (LogOFF)
      selection-screen pushbutton 55(20) b_quit
                       user-command quit modif id adm.
    selection-screen end   of line.
  selection-screen end   of block sysexit.
*-Without confirmation
  parameter p_silent as checkbox default space.
selection-screen end   of screen 105.

selection-screen begin of tabbed block tb1 for 14 lines.
  sscrtab tabs1 ucom1 101.
  sscrtab tabs2 ucom2 102.
  sscrtab tabs3 ucom3 103.
  sscrtab tabs4 ucom4 104.
  selection-screen tab (5) tabs5
              user-command ucom5 default screen 105 modif id adm.
selection-screen end   of block tb1.

************************************************************************
* Event Handlers                                                       *
************************************************************************
initialization.
  perform init.

*-----------------------------------------------------------------------
at selection-screen output.
  perform at_selection_screen_output.

**t selection-screen on p_chkpar.
*  if p_chkpar is initial and keepalive <> 0.
*    app_log_z2_1 '048' keepalive.
*    message i048 with keepalive.
*  endif.

*-----------------------------------------------------------------------
*t selection-screen on radiobutton group radi.
* if p_prn = 'X'. message i???. endif.

*-----------------------------------------------------------------------
*t selection-screen on exit-command.
*-This is a small joke: issue message on exit command
* if sy-datum+4(4) = '0401'.             "If date = '1 April'
*   define joke. pop_txt = &1. end-of-definition. "JOKE
*   case sy-uzeit+5(1).
*     when 1.
*       joke 'Do you hear strange noise from your hard drive?'.
*     when 2.
*       joke 'New user detected and installed'.
*     when 3.
*       joke 'Keep your hair on! Wait at least 55 minutes...'.
*     when 4.
*       joke 'The hole detected in your monitor!'.
*     when 5.
*       joke 'Where you go? SAP cannot watch over you there!'.
*     when others.
*       joke 'Unknown user connected to your PC. Thanks to SAP!'.
*   endcase.
*   message s030 with pop_txt.
**else.
**-'Have a nice day!'
**  message s087.
* endif.

*-----------------------------------------------------------------------
at selection-screen on p_rows.
  if p_rows < 0.
*   app_log_z2_1 '030' text-775.
*   message e030 with 'Number of hits can''t be negative'(775).
    app_log_00_0 '126'.
*--'Negative values not allowed'
    message e126(00).
  endif.

*-----------------------------------------------------------------------
*at selection-screen on help-request for p_chkpar.
*  call function 'PFL_SHOW_PARAMETER_DOCU'
*       exporting
*         parameter_name = s_keepal
*       exceptions
*         others         = 1
*         .
*  if sy-subrc <> 0.
**   message i031 with s_keepal ': documentation not found!'(827).
**--'Timer for check unused TCP/IP-connections'
*    app_log_z2_0 '099'.
*    message s099.
*  endif.

*-----------------------------------------------------------------------
at selection-screen on help-request for p_upload.
  if p_phones is initial.
    app_log_z2_2 '097' loctab key_phones.
*--'Full path must be set in tab. &1 under key &2'
    message s097 with loctab key_phones.
  else.
    app_log_z2_2 '031' text-998 p_phones.
    message s031 with 'Upload from'(998) p_phones.
  endif.

*-----------------------------------------------------------------------
at selection-screen on value-request for p_phones.
  perform get_source_file.

*-----------------------------------------------------------------------
*t selection-screen on help-request for p_prn.
* message s030 with 'This parameter means: ...'.

*-----------------------------------------------------------------------
at selection-screen.
  perform at_selection_screen.

*-----------------------------------------------------------------------
start-of-selection.
  perform start_of_selection using 'X'.

*-----------------------------------------------------------------------
end-of-selection.

*-----------------------------------------------------------------------
at line-selection.                    "When user clicked on a line
  perform at_line_selection.          "Only works if GUI-status not set

*-----------------------------------------------------------------------
at user-command.
  perform at_user_command.

*-----------------------------------------------------------------------
top-of-page.                          "Page header
  perform top_of_page.

*-----------------------------------------------------------------------
top-of-page during line-selection.    "Page header when resorting
  perform top_of_page.

************************************************************************
* Routines                                                             *
************************************************************************
form clear_filter.
*-Clear select-options
  refresh: so_bname, so_ustyp, so_class, so_group.
endform. "CLEAR_FILTER
*-----------------------------------------------------------------------
form init_filter.
  perform clear_filter.

  app_filter1  sapstar.
* app_filter1  sapcpic.
  app_filter1  ddic.
  app_filter1  tmsadm.
  app_filter1  earlywatch.

  app_filter2 'A'.
  app_filter2 'S'.
endform. "INIT_FILTER
*-----------------------------------------------------------------------
form get_cpcomment using v_codepage like tcp00-cpcodepage
                changing value(v_comment)
                         .
  data cpcomment like tcp00-cpcomment.
  clear cpcomment.
  select single cpcomment into cpcomment
                          from tcp00
                          where cpcodepage = v_codepage
                                .
  if sy-subrc = 0. v_comment = cpcomment. endif.
endform. "GET_CPCOMMENT
*-----------------------------------------------------------------------
form get_codepages.
*-Get App. Server code page, SAPGUI code page and NLS locale
  call 'CUR_LCL'
*   id 'LANG'     field cur_lang
    id 'CODEPAGE' field cur_app_cp
    id 'LOCALE'   field cur_locale
    id 'GUICP'    field cur_gui_cp
*   id 'APDISPCP' field cur_ap_disp_cp
*   id 'APPROPCP' field cur_ap_prop_cp
*   id 'APINPUCP' field cur_ap_inpu_cp
*   id 'RC'       field rsts_rc
*   id 'ERRMSG'   field rsts_errmsg
    .
  p_appcp  = cur_app_cp.
  p_guicp  = cur_gui_cp.
  p_locale = cur_locale.

* perform get_cpcomment using p_appcp changing c_appcp.
* perform get_cpcomment using p_guicp changing c_guicp.
endform. "GET_CODEPAGES
*-----------------------------------------------------------------------
form depend_expand.
  l01 =       3. r01 = l01 + 13. "strlen( text-202 ) + 1. "BNAME
  lm1 = r01 + 1. rm1 = lm1 +  1.                          "MARK CheckBox
  l02 = lm1 + 3. r02 = l02 + 15. "strlen( text-003 )      "NAME_LAST
  l03 = r02 + 1. r03 = l03 + 23. "strlen( text-004 ) - 2. "NAME_FIRST
  l04 = r03 + 2. r04 = l04 +  8. "strlen( text-005 ) - 2. "TEL_NUMBER
  l05 = r04 + 2. r05 = l05 +  4. "strlen( text-006 ) - 2. "TEL_EXTENS
  l06 = r05 + 2. r06 = l06 + 39. "strlen( text-008 ) - 2. "FUNCTION
  l07 = r06 + 2. r07 = l07 + 39. "strlen( text-013 ) - 2. "DEPARTMENT
  l08 = r07 + 2. r08 = l08 +  6. "strlen( text-018 ) - 2. "BUILDING
  l09 = r08 + 2. r09 = l09 +  4. "strlen( text-019 ) - 2. "ROOMNUMBER
  l10 = r09 + 2. r10 = l10 + 18. "strlen( text-900 ) - 2. "TRDAT
* l11 = r10 + 2. r11 = l11 +  ?. "strlen( text-901 ) - 2. "LTIME
  l12 = r10 + 2. r12 = l12 + 11. "strlen( text-027 ) - 2. "MODBE
  l13 = r12 + 2. r13 = l13 + 18. "strlen( text-028 ).     "MODDA

  l14 = r13 + 2. r14 = l14 + 11. "strlen( text-___ ) - 2. "ANAME
  l15 = r14 + 2. r15 = l15 +  9. "strlen( text-___ ).     "ERDAT

  if p_expand is initial.
    expa_symb =  sym_right_triangle.
    q_expa    = 'Extend'(667).
    uline_m   =  sy-linsz - 2 - 7.
*---I think, auto sort during EXPAND/SQUEEZE is not useful :-<
*   if sav1 = 'TEL_NUMBER'. sav1 = 'TEL_NUMDIS'. endif.
  else.
    add 7 to:
           r04
    , l05, r05
    , l06, r06
    , l07, r07
    , l08, r08
    , l09, r09
    , l10, r10
*   , l11, r11
    , l12, r12
    , l13, r13
    , l14, r14
    , l15, r15
    .
    expa_symb =  sym_left_triangle.
    q_expa    = 'Squeeze'(668).
    uline_m   =  sy-linsz - 2.
*---I think, auto sort during EXPAND/SQUEEZE is not useful :-<
*   if sav1 = 'TEL_NUMDIS'. sav1 = 'TEL_NUMBER'. endif.
  endif.
endform. "DEPEND_EXPAND
*-----------------------------------------------------------------------
form depend_cpynam.
  if p_cpynam is initial.
    qcpy_symb =  sym_glasses.
    q_qcpy    = 'Navigation mode is active'(395).
  else.
    qcpy_symb =  sym_documents.
    q_qcpy    = 'Quick copy mode is active'(396).
  endif.
endform. "DEPEND_CPYNAM
*-----------------------------------------------------------------------
data ps_bar type i.   "Icon bar

form set_ps_tb1.
  data lim like sy-scols.    "Right margin

  if sy-scols > sy-linsz. lim = sy-linsz.
                    else. lim = sy-scols. endif.
* ps_bar = sy-colno.
  ps_tb1 = lim - bar_width.
  if f_docked is initial. ps_tb1 = ps_bar. endif.
* if ps_tb1 < ps_bar or f_docked is initial. ps_tb1 = ps_bar. endif.
  if ps_tb1 < ps_bar. ps_tb1 = ps_bar. endif.
endform. "SET_PS_TB1
*-----------------------------------------------------------------------
form init.
*-My Report ID, my Application Server's Host
  g_repid = sy-repid.
  p_host  = sy-host.

*-Get installed languages
  move sy-langu to langu.           "Set logon language as initial
  clear cant_switch_lang.

  get_param 'zcsa/installed_languages' inst_lang.

  lang_len = strlen( inst_lang ).   "Length of a languages-string
  if lang_len = 0.
    cant_switch_lang = 'X'.
  else.
    search inst_lang for sy-langu.  "Get position of logon language
    if sy-subrc = 0.
      lang_pos = sy-fdpos.          "at installed languages string
    else.
      cant_switch_lang = 'X'.
    endif.
  endif.

*-Get Profile Parameter 'auth/new_buffering'
  get_param 'auth/new_buffering' new_buffering.
*-Set up output position PS_TB1
  perform set_ps_tb1.

*-Get program title
  perform get_program_title using g_repid langu changing p_title.
  move p_title to c_titl.

*-Get original system, master language
  select single srcsystem
                masterlang
                into (p_srcsy, p_lang)
                from tadir
                where pgmid    = 'R3TR'
                  and object   = 'PROG'
                  and obj_name =  g_repid
                      .
  if sy-subrc <> 0.
    move '?' to:
      p_srcsy
    , p_lang
    .
  endif.

*-Get Created by/Date, Changed by/Date, Build, Sel.-screen generat. info
  select single
    cnam                 "Created by
    cdat                 "Created on
    unam                 "Last changed by
    udat                 "Last changed on
    vern                 "Version number
    sdate                "Standard selection screen generation: Date
    stime                "Standard selection screen generation: Time
    into (p_cnam
        , p_cdat
        , p_unam
        , p_udat
        , p_vern
        , p_sdat
        , p_stim)
    from trdir
    where name = g_repid
          .
  if sy-subrc <> 0.
    move '?' to:
      p_cnam
    , p_cdat
    , p_unam
    , p_udat
    , p_vern
    , p_sdat
    , p_stim
    .
  else.
*---Format Date
    data tmp_datum(10).
    write p_udat to tmp_datum.
*---Version number (build): Remove leading zeros
    shift p_vern left deleting leading '0'.
*---Format Time
    write p_stim to p_stim using edit mask t_mask.
    concatenate tmp_datum
                p_unam
               'Build:'(882)
                p_vern
           into q_info_prog
                separated by space
                .
    condense q_info_prog.
  endif.

*-Get Customer Number
  perform read_customer.

  repl text-016 sy-sysid   c_mansys.
  repl text-063 v_customer c_cust.

  perform depend_cpynam.
  perform depend_expand.
  perform depend_range using ' '.

*-Set icon depending on F_CHKADDR flag
  perform set_chck_icon.

*-Get my system name (server_SID_XX)
  get_param 'rdisp/myname' myname.

*-Get host IP address
  perform get_host_ip using sy-host changing host_ip.

*-Get 'rdisp/keepalive'
* perform get_keepalive changing keepalive.

*-Get Kernel Patch Level
  call 'ThSysInfo'
    id 'OPCODE'          field opcode_saprel
    id 'KERN_REL'        field kern_rel
*   id 'KERN_DBLIB'      field kern_dblib
*   id 'KERN_COMP_ON'    field kern_comp_on
    id 'KERN_COMP_TIME'  field kern_comp_time
    id 'KERN_PATCHLEVEL' field kern_patch
*   id 'SUPP_DB_SAP'     field supp_db_sap-*sys*
*   id 'SUPP_DB_VENDOR'  field supp_db_vendor-*sys*
*   id 'SUPP_OP_SYS'     field supp_op_sys-*sys*
*   id 'PATCHCOMMENT'    field patchcomment-*sys*
    .
*-Generate platform description (Operation System and Database System)
  concatenate sy-opsys '/' sy-dbsys
         into platform
              separated by space
              .
*-Generate kernel info (Kernel Release and Kernel Patch Level)
  concatenate  kern_rel
*             '/'
               kern_patch
         into  kerninfo
               separated by space
               .
*  concatenate 'Compiled on'(110)
*               kern_comp_time
**              kern_comp_on
*         into  q_kern
*               separated by space
*               .
*-Get Levels of Installed Components/Support Packages
  perform get_sp_info.

*-Get My Attributes
  perform get_my_attr.

*-If this report started from tr. SE38 (ABAP-Editor) or from tr. SA38
* (Report Launcher) then fill R_TCODE with first found transaction code
* associated with this report else fill with current transaction code
  if sy-tcode = 'SE38' or sy-tcode = 'SA38'.
    select tcode into (r_tcode)
                 from tstc up to 1 rows
                 where pgmna = sy-repid
                       .
    endselect.
*   if sy-subrc <> 0. clear r_tcode. endif.
  else.
    move sy-tcode to r_tcode.
  endif.

*-Check for existence of satellite functions in the system
  fm_det 'Z_GET_PERSONAL_INFO' fm_personal.
  fm_det 'Z_CHK_USR'           fm_auth_chk.
  fm_det 'Z_SHOW_DOC'          fm_show_doc.
* fm_det 'Z_TIME_DIFF'         fm_time_dif.
  fm_det 'Z_GET_SMTP_ADDR'     fm_smtp_adr.
  fm_det 'Z_RESET_PASSWORD'    fm_reset_pw.
  fm_det 'Z_ZUSRMON_TO_EXCEL'  fm_to_excel.
  fm_det 'Z_TH_POPUP'          fm_th_popup.
  if fm_th_popup-exists is initial.
    fm_det 'TH_POPUP'          fm_th_popup.
  endif.
  fm_det 'Z_TH_POPUP_MASS'     fm_th_pop_m.

*-Check for existence of custom transactions in the system
  tr_det 'SM12'     tr_sm12.
  tr_det 'SM13'     tr_sm13.
  tr_det 'SM12'     tr_sm12.
* tr_det 'SP01'     tr_sp01.
* tr_det 'ST01'     tr_st01.
  tr_det 'ST22'     tr_st22.
* tr_det 'SU10'     tr_zlock.

*-Check whether SAPGUI for Java is used
  call function 'GUI_HAS_JAVABEANS'
       importing
         return = f_javagui
         .
  if f_javagui = 'X'. clear p_upload. endif.

*-Get locations of resources
  perform get_location using key_vnc    changing v_vnc.
  perform get_location using key_phones changing p_phones.
  perform get_location using key_photos changing v_photos.

*-Does history table exist?
  perform check_hist_tab.

*-Support for ListBox
**select mandt mtext from t000 into (w_line-key, w_line-text).
* select mandt       from t000 into (w_line-key).
*   append w_line to it_val.
**  check p_mandt is initial.
*   p_mandt = w_line-key.
* endselect.

  tabs1  = '@4G@Filter'(806).       "@4G@ ICON_FILTER
  tabs2  = '@MS@Layout'(802).       "@MS@ ICON_BW_EXCEPTION_MONITOR
  tabs3  = '@45@Miscellaneous'(801)."@45@ ICON_TOOLS
  tabs4  = '@BY@Expert'(803).       "@BY@ ICON_WIZARD
  tabs5  = '@3X@'(069).             "@3X@ ICON_CLOSE

  b_onli = '@15@Execute'(039).      "@15@ ICON_EXECUTE_OBJECT
  b_fdel = 'Clear'(923).
  b_fset = 'Preset'(924).
  b_impr = '@2V@Paste'(387).
  b_impa = '@8G@Add'(392).
  b_nous = '@11@'.
  b_snls = 'Get information about code pages and NLS locale'(884).
  b_time = '@42@'(067).             "@42@ ICON_REFRESH
  b_quit = '@33@Quit!'(080).        "@33@ ICON_SYSTEM_MODUS_DELETE

*                                    @IX@ ICON_HLP
*                                    @0S@ ICON_INFORMATION
*                                    @8Q@ ICON_MESSAGE_QUESTION_SMALL
*                                    @1C@ ICON_MESSAGE_QUESTION
*                                    @35@ ICON_SYSTEM_HELP
* c_doc  = '@IX@Help is available on the main screen too'(062).
  c_pwd  = 'Password'(060).

  c_doc1 = '====================================================='(771).
  c_doc2 = '@BF@Expert mode is required for additional abilities'(772).
  c_doc3 = 'such as submitting some statistical reports'(773).
  c_doc4 = 'and more. Enter password and get ALL of the power!'(774).
  c_doc5 = '====================================================='(771).

  c_doc6 =
  '@8O@WARNING!!! This closes all of your sessions without saving'(076).

  c_doc7 =
  '@8O@and leaves the system! Any unsaved data will be lost!'(078).

*  c_typ1 = '@KW@A - Dialog'(807).
*  c_typ2 = '@KX@B - System user (internal RFC and bgr. process.)'(808).
*  c_typ3 = '@KY@C - Communication user (external RFC)'(809).
*  c_typ4 = '@KZ@L - Reference user'(810).
*  c_typ5 = '@L0@S - Service user'(811).

  c_prog = 'Program__'(402).
  c_crea = 'Created by'(144).
  c_chan = 'Changed by'(145).
  c_srcs = 'in system'(146).
  c_lang = 'in language'(147).
  c_vern = 'Build no.'(148).
  c_sscr = 'Sel.-screen generated on'(149).
  c_stim = 'at'(150).

* get_current_date.

  fill_def_icon d_icon1 'used by default'(081) c_icon1.
  fill_def_icon d_icon2  text-081              c_icon2.

*-----------function text (menu), icon, icon text, quick info
  fill_btn 'Hint'(000)                       "Menu function text
           '@BF@'      "@BF@ or @AI@ or @5Y@ "Icon ID
            space                            "Icon text
            text-000                         "Quick info
            sscrfields-functxt_01
            .
  fill_btn 'DEV'(751)                        "Menu function text
           '@45@'      "@45@ ICON_TOOLS      "Icon ID
            text-751                         "Icon text
           'RFC to DEV system'(064)          "Quick info
            sscrfields-functxt_02
            .
  fill_btn 'QAS'(752)                        "Menu function text
           '@12@'      "@12@ ICON_TEST       "Icon ID
            text-752                         "Icon text
           'RFC to QAS system'(065)          "Quick info
            sscrfields-functxt_03
            .
  fill_btn 'PRD'(753)                        "Menu function text
           '@9Y@'      "@9Y@ ICON_ACTIVITY   "Icon ID
            text-753                         "Icon text
           'RFC to PRD system'(066)          "Quick info
            sscrfields-functxt_04
            .
  perform refresh_time_display.

*-Build salut
  perform get_user_name
                  using sy-mandt      sy-uname
               changing my_name_first my_name_last
                        .
  if my_name_first is initial.      "If the first name is empty,
    move sy-uname      to username. "then use logon name,
  else.
    move my_name_first to username. "else use the first name
  endif.
  concatenate '@8P@' username ',' into salut.
  point_bname = sy-uname.           "Initial value for marked user name

**-Fill internal table that will be used when calling SU01
*  cls bdcdata.                      "Cleanup internal table
** bdcdata-program  = 'SAPLSUU5'.    "Func. group used in SU01
** bdcdata-dynpro   = '0050'.        "Screen number
** bdcdata-dynbegin = 'X'.
*  bdcdata-program  = 'SAPMSUU0'.    "Report used in SU01_NAV
*  bdcdata-dynpro   = '1000'.        "Screen number
*  bdcdata-dynbegin = 'X'.
*  append bdcdata.

*-Fill internal table with forbidden function codes
  refresh extab1.    "Not expert, client <> current
  app1 'SU01'.
  app1 'AUTH'.
* app1 'SEND'.
* app1 'BROA'.
  app1 'LOCK'.
  app1 'ULCK'.
  app1 'U003'.
  app1 'U005'.
* app1 'U006'.
  app1 'U008'.
  app1 'U009'.
  app1 'U010'.
  app1 'RESE'.
  app1 'COPY'.
* app1 'MORE'.
  app1 'DALV'.
* app1 'MLOG'.
* app1 'DLOG'.

  refresh extab2.    "Expert,     client <> current
  app2 'SU01'.
  app2 'AUTH'.
  app2 'LOCK'.
  app2 'ULCK'.
  app2 'RESE'.
  app2 'COPY'.
* app2 'MORE'.
  app2 'DALV'.

  refresh extab3.    "Not expert, client == current
* app3 'SEND'.
* app3 'BROA'.
  app3 'U003'.
  app3 'U005'.
* app3 'U006'.
  app3 'U008'.
  app3 'U009'.
  app3 'U010'.

  if enable_chk1 = 'X'.
    case sy-uname.
      when sapstar
        or admin_1
        or admin_2
        or admin_3
        or admin_4
        or admin_5
        or admin_6
        or admin_7
        or admin_8
        or admin_9
           .
      when others.  app3 'RESE'.
                    app3 'COPY'.
*                   app3 'MORE'.
*                   app3 'LOCK'.
*                   app3 'ULCK'.
    endcase.
  endif.
* app3 'MLOG'.
* app3 'DLOG'.

*-Check authorizations
  authority-check object obj_usradm
    id 'CLASS' dummy
    id 'ACTVT' field '05'
    .
  if sy-subrc <> 0.
    app3 'LOCK'.
    app3 'ULCK'.
  endif.

  perform init_filter.

*-Users to exclude from mass locking/unlocking
  cls avoid.

*-Exclude built-in SAP users
  app_avoid sapstar.
  app_avoid sapcpic.
  app_avoid ddic.
  app_avoid tmsadm.
  app_avoid earlywatch.

*-Exclude admins
  app_avoid admin_1.
  app_avoid admin_2.
  app_avoid admin_3.
  app_avoid admin_4.
  app_avoid admin_5.
  app_avoid admin_6.
  app_avoid admin_7.
  app_avoid admin_8.
  app_avoid admin_9.

*-Exclude own account
  app_avoid sy-uname.

  cls msg_log.
endform. "INIT
*-----------------------------------------------------------------------
form at_selection_screen_output.
  loop at screen.
*---Batch processing of screen fields: reference by GROUP1 (modif id).
*   Modify all elements those included into group under modif id BLU
    case screen-group1.
      when 'BLU'.
*-------Set highlight attribute (Light Blue) for all those fields
        screen-intensified = '1'.
        modify screen.

      when 'OFF'.
*-------Set P_TIME to read only
        screen-input  = '0'.
        modify screen.

      when 'NLS'.
        if    p_appcp  is initial
          and p_guicp  is initial
          and p_locale is initial
          .
*---------Hide CODE PAGE and NLS LOCALE fields
          screen-active = '0'.
        else.
*---------Show CODE PAGE and NLS LOCALE fields
          screen-active = '1'.
        endif.
*-------Set CODE PAGE and NLS LOCALE fields to read only
        screen-input = '0'.
        modify screen.

      when 'BLS'.
        if    p_appcp  is initial
          and p_guicp  is initial
          and p_locale is initial
          .
*---------Show button B_SNLS
          screen-active = '1'.
        else.
*---------Hide button B_SNLS
          screen-active = '0'.
        endif.
        modify screen.

      when 'EXP'.
*-------Mask P_PWD screen field
        screen-invisible = '1'.
        modify screen.

      when 'ADM'.
        if ( enable_chk1 is initial
             or sy-uname = sapstar
             or sy-uname = admin_1
             or sy-uname = admin_2
             or sy-uname = admin_3
             or sy-uname = admin_4
             or sy-uname = admin_5
             or sy-uname = admin_6
             or sy-uname = admin_7
             or sy-uname = admin_8
             or sy-uname = admin_9
             or sy-uname = power_1
             or sy-uname = power_2
             or sy-uname = power_3
             or sy-uname = power_4
             or sy-uname = power_5
             or sy-uname = power_6
             or sy-uname = power_7
             or sy-uname = power_8
*            or sy-uname = rfc_user
           ).
*---------Set highlight attribute (Light Blue) for all those fields
          screen-intensified = '1'.
*          if screen-name = 'P_UPLOAD' and f_javagui = 'X'.
*            screen-input = '0'.
*          endif.
        else.
**---------Hide P_UPLOAD screen field (and its comment)
*          if screen-name = 'P_UPLOAD'.
*            screen-input = '0'.
*          endif.
          screen-active = '0'.
        endif.
        modify screen.
    endcase.

*---Individual processing of screen field: reference by NAME
    case screen-name.
      when 'P_POINT'.
        if p_prn = 'X'.
          screen-input = '0'. "Disable input to field P_POINT
          modify screen.
        endif.
      when 'P_UPLOAD'.
        if f_javagui = 'X'.
*---------Redundant clear for safety
          clear p_upload.
          screen-input = '0'.
          modify screen.
        endif.
      when 'P_PHONES'.
        if p_upload = 'X'.
          screen-input = '1'.
        else.
          screen-input = '0'.
        endif.
        modify screen.
    endcase.
  endloop.

  if    p_appcp  is initial
    and p_guicp  is initial
    and p_locale is initial
    .
  else.
    perform get_cpcomment using p_appcp changing c_appcp.
    perform get_cpcomment using p_guicp changing c_guicp.
  endif.

*-Support for ListBox
* call function 'VRM_SET_VALUES'
*      exporting
*        id     = 'P_MANDT'
*        values =  it_val
*        .
endform. "AT_SELECTION_SCREEN_OUTPUT
*-----------------------------------------------------------------------
form at_selection_screen.
  perform fill_icons.
  perform fill_mandt_f.

  case sscrfields-ucomm.              "On selection-screen user pressed
    when 'FC01'.                      "Button #1
      clear sscrfields-ucomm.
      app_log_z2_1 '014' x_tcode.
*     message i014 with x_tcode.      "Hint to skip selection-screen
      call function 'SMPO_DISPLAY_ONE_MESSAGE'
           exporting
             titlebar =  text-000     "Hint
             msgty    = 'I'           "Type I
             msgid    = 'Z2'          "Message class
             msgno    = '014'         "Message number
             msgv1    =  x_tcode      "Argument 1
*            msgv2    =  space        "Argument 2
*            msgv3    =  space        "Argument 3
*            msgv4    =  space        "Argument 4
             .

    when 'FC02'.                      "Button #2
      clear sscrfields-ucomm.         "--> jump to DEV
      perform remote_transaction using r_tcode dest_dev.

    when 'FC03'.                      "Button #3
      clear sscrfields-ucomm.         "--> jump to QAS
      perform remote_transaction using r_tcode dest_qas.

    when 'FC04'.                      "Button #4
      clear sscrfields-ucomm.         "--> jump to PRD
      perform remote_transaction using r_tcode dest_prd.

    when 'UCOM4'.
*     clear sscrfields-ucomm.
      perform refresh_time_display.

*   when 'UCOM5'.
*     clear sscrfields-ucomm.
*     set cursor field 'B_QUIT'.

    when 'QUIT'.
      clear sscrfields-ucomm.
      if p_silent is initial.
        confirm_step 'N'
                     'Unsaved data will be lost'(073)
                     'Do you want to log off?'(074)
                     'Log Off'(075)
                      .
        if ans = 'J'. perform log_off. endif.
      else. perform log_off. endif.

*---Import users from clipboard (REPLACE mode)
    when 'IMPR'.
      clear sscrfields-ucomm.
      perform import_so_bname using 'X'.
*     cur_field = 'SO_BNAME-LOW'.

*---Clear users
    when 'NOUS'.
      clear sscrfields-ucomm.
      refresh so_bname.
*     cur_field = 'SO_BNAME-LOW'.

*---Import users from clipboard (ADD mode)
    when 'IMPA'.
      clear sscrfields-ucomm.
      perform import_so_bname using ' '.
*     cur_field = 'SO_BNAME-LOW'.

*---Clear filter  (Users and Types)
    when 'FDEL'.
      clear sscrfields-ucomm.
      perform clear_filter.
*-----Only clean up current Variant Name when requested explicitly
*     NOT in form CLEAR_FILTER to keep SY-SLSET during SUBMIT
      clear sy-slset.
*     export sy-slset to memory id 'SLS'.

*---Preset filter (Users and Types)
    when 'FSET'.
      clear sscrfields-ucomm.
      perform init_filter.
*-----Only clean up current Variant Name when requested explicitly
*     NOT in form CLEAR_FILTER to keep SY-SLSET during SUBMIT
      clear sy-slset.
*     export sy-slset to memory id 'SLS'.

*---Refresh time display
    when 'TIME'.
      clear sscrfields-ucomm.
      perform refresh_time_display.

*---Get Code Pages
    when 'SNLS'.
      clear sscrfields-ucomm.
      perform get_codepages.

*   when  space.
*     if sy-ucomm is initial and tb1-activetab <> 'UCOM1'.
*       sscrfields-ucomm = 'ONLI'.
*     endif.
  endcase.
  perform compute_threshold_date.
endform. "AT_SELECTION_SCREEN
*-----------------------------------------------------------------------
form fill_icons.
  check_icon d_icon1 p_icon1 v_icon1. "Default, Specified, Assigned
  check_icon d_icon2 p_icon2 v_icon2.
endform. "FILL_ICONS
*-----------------------------------------------------------------------
form fill_mandt_f.
  mandt_f = p_mandt.
endform. "FILL_MANDT_F
*-----------------------------------------------------------------------
form log_off.
  constants silent_logoff like sy-ucomm value '/NEX'.

  set_fcode_ex silent_logoff 1.
  if sy-subrc <> 0.
    app_log_z2_008 silent_logoff.
*--'Error: &1'
    message i008 with silent_logoff.
  endif.
endform. "LOG_OFF
*-----------------------------------------------------------------------
form refresh_time_display.
  write sy-uzeit to p_time using edit mask t_mask.
endform. "REFRESH_TIME_DISPLAY
*-----------------------------------------------------------------------
define notify_about_client.
  app_log_z2_1 '096' sy-mandt.
*-'The only data for logon client (&) can be shown here!'
  message i096 with sy-mandt.
end-of-definition. "NOTIFY_ABOUT_CLIENT
*-----------------------------------------------------------------------
form start_of_selection using value(init_flg).
  perform check_authorization.
  perform set_color_for_header.

*-Checking additional workload-depending restrictions is switched OFF
* include zqueryrun.          "<== After standard authorization check

  perform get_intens.
  perform upload_phones. "Loading from PC eliminates expert mode warning
  perform initial_output using init_flg.

  if p_jump = 'X'. set_fcode 'SESS'. endif.
endform. "START_OF_SELECTION.
*-----------------------------------------------------------------------
define toggle_cmd_flag_icon.
  perform toggle_flag changing &1.
  perform modify_mode_icon.
end-of-definition. "TOGGLE_CMD_FLAG_ICON
*-----------------------------------------------------------------------
form toggle_cmd_disable.
  toggle_cmd_flag_icon f_cmd_disable.
endform. "TOGGLE_CMD_DISABLE
*-----------------------------------------------------------------------
form toggle_cmd_autoscan.
  toggle_cmd_flag_icon f_cmd_autoscan.
endform. "TOGGLE_CMD_AUTOSCAN
*-----------------------------------------------------------------------
form toggle_cmd_autocrop.
  toggle_cmd_flag_icon f_cmd_autocrop.
endform. "TOGGLE_CMD_AUTOCROP
*-----------------------------------------------------------------------
form at_user_command.
  if not busy_cnt is initial.
    case sy-ucomm.
      when 'SELE'
        or 'REFR'
        or 'AREF'
        or 'OKAY'
        or 'SESS'
        or 'LANG'
        or 'MOVE'
        or 'WAST'
        or 'NOIP'
        or 'MTCH'
        or 'WIDE'
        or 'CANCEL'.
        .
      when others. deny_because_of_arfc.
    endcase.
  endif.

  case sy-pfkey.
    when 'MAIN'.
      case sy-ucomm.
        when 'SELE'. perform at_line_selection.
        when 'REFR'. perform cmd_refresh_list.
        when 'VISI'. perform toggle_html_pane_main.
        when 'CONN'. perform toggle_badres.
        when 'ALTP'. perform toggle_altpict.
        when 'ALTB'. perform toggle_altbkgr.
        when 'SETB'. perform change_background.
        when 'SIZE'. perform toggle_resize.
        when 'OKAY'. perform process_input_m using space.
        when 'TLBR'. perform toggle_docked.
        when 'CMDL'. perform toggle_cmdl.
        when 'CMDH'. perform toggle_flag changing f_cmd_highlight.
        when 'CMDR'. perform toggle_range.
        when 'CMDS'. perform toggle_flag changing f_cmd_scroll.
        when 'CMDD'. perform toggle_cmd_disable.
        when 'CMDA'. perform toggle_cmd_autoscan.
        when 'CMDC'. perform toggle_cmd_autocrop.
        when 'CMD!'. perform toggle_cmd_mode.
        when 'QCPY'. perform cmd_cpynam.
        when 'SEND'. perform send_popup.
        when 'SENL'. perform log_failed_alv using ' '.
        when 'MARK'. perform toggle_user.
        when 'SELA'. perform cmd_select_all.
        when 'SELN'. perform cmd_select_none.
        when 'SELI'. perform cmd_invert.
        when 'SELB'. perform select_block.
        when 'SELO'. perform cmd_select_online.
        when 'SELR'. perform cmd_select_with_refuser.
        when 'YELL'. perform cmd_select_yellow.
        when 'RED '. perform cmd_select_red.
        when 'EXCL'. perform exclude_from_list.
        when 'CROP'. perform crop_list.
        when 'CHCK'. perform toggle_chkaddr.
                     perform print_table.
        when 'KEEP'. perform toggle_keep.
        when 'RESE'. perform reset_selected_users.
        when 'COPY'. get_and_check_sel_bname.
                     perform query_user_copy using sel_bname tmp_bname.
        when 'BROA'. perform send_broadcast_popup_msg.
        when 'ACTI'. perform show_user_activity.
        when 'DETA'. get_and_check_sel_bname.
                     perform show_user_details using p_mandt sel_bname.
        when 'MAIL'. perform mail_to.
        when 'MORE'. perform extended_action.
        when 'AUTH'. get_and_check_sel_bname.
                     perform display_user_auths using sel_bname.
        when 'SESS'. perform show_active_sessions.
        when 'SU01'. perform call_su01.
        when 'SM50'. perform call_sm50.
        when 'SM04'. perform call_sm04.
        when 'SM02'. perform call_sm02.
        when 'ST22'. perform call_st22.
        when 'SM12'. perform call_sm12.
        when 'SM13'. perform call_sm13.
        when 'OS01'. perform call_os01.
        when 'UAGR'. perform show_roles_main.
*       when 'PFCG'. perform call_pfcg.
*       when 'ZPOP'. perform call_zpop.
*       when 'ZLOC'. perform call_zlock.
        when 'DALV'. perform display_alv.
        when 'MLOG'. perform show_log.
        when 'DLOG'. perform clear_log.
        when 'DOCS'. perform show_documentation.
        when 'SSCR'. perform call_selection_screen.
*       when 'LEFT'. scroll list left  by 8 places. "ok-code 'PS-8'
*       when 'RIGH'. scroll list right by 8 places. "ok-code 'PS+8'
        when 'AUTO'. perform toggle_flag changing p_refr.
                     perform report_p_refr_status.
        when 'AREF'. perform toggle_aref.
        when 'AGRF'. perform toggle_agrf.
        when 'PATH'. perform change_path_to_photos.
        when 'EXTE'. perform change_extension.
        when 'LANG'. perform cmd_next_language_m.
        when 'MOVE'. perform move_pointer.
        when 'LAY1'. if p_prn is initial.
                       perform toggle_flag changing p_point.
                       perform print_table.
                     else.
                       app_log 'SH' '100' space space space space.
*---------------------'Function not currently available.'
                       message s100(sh).
*---------------------'This function is not possible'
*                      message s127(00).
*---------------------'Function not yet supported'
*                      message s620(vw).
                     endif.
        when 'LAY2'. perform toggle_flag changing p_scroll.
                     perform print_table.
        when 'LAY3'. perform toggle_flag changing p_hot.
                     perform print_table.
        when 'LAY4'. perform toggle_flag changing p_intens.
                     perform get_intens.
                     perform set_contrast.
        when 'RDEV'. perform remote_transaction using r_tcode dest_dev.
        when 'RQAS'. perform remote_transaction using r_tcode dest_qas.
        when 'RPRD'. perform remote_transaction using r_tcode dest_prd.
        when 'PERI'. perform set_period.
        when 'PHON'. "erform upload_phones.
                     perform change_path_to_phones.
        when 'LOCK'. perform lock_unlock_selected_user
                       using c_locked_by_admin.
        when 'ULCK'. perform lock_unlock_selected_user
                       using c_not_locked.

*-------Get Single Statistical Records
        when 'STAT'. get_and_check_sel_bname.
                     perform stat_records using sel_bname.

*-------Check the passwords of users SAP* and DDIC in all clients
        when 'U003'. perform submit_report using 'RSUSR003'.

*-------List of Users With Critical Authorizations (variant 1)
        when 'U005'. perform confirm_program_run using 'RSUSR005'.
                     case ans.
                       when 'J'.
                         perform submit_report using 'RSUSR005'.
                       when others.
                         perform action_cancelled.
                     endcase.

*-------List of User Master Records Locked Due to Incorrect Logon
        when 'U006'. perform submit_report using 'RSUSR006'.

*-------Critical Combinations of Authorizations for Transactions
        when 'U008'. perform submit_report using 'RSUSR008'.

*-------List of Users With Critical Authorizations (variant 2)
        when 'U009'. perform submit_report using 'RSUSR009'.

*------Transaction Lists According to Selection With User,Profile or Obj
        when 'U010'. get_and_check_sel_bname. " commit work.
                     perform list_allowed_tcodes
                       using p_mandt sel_bname
                             .
        when 'FILE'. perform show_phones_file_content.
*       when 'HTML'. perform write_to_html.
        when 'EXCE'. perform export_to_excel_main.
        when 'CLPB'. perform export_to_clipboard tables it using ' '.
        when 'CTLC'. perform export_to_clipboard_main.
*       when 'CTLV'. perform mark_from_clipboard_main.
        when 'CTLV'. perform mark_from_clipboard.
        when 'IMPM'. perform toggle_impm.
        when 'CANCEL'. perform at_main_cancel.
        when others. perform other_okcode.
      endcase.
    when 'USER'.
      case sy-ucomm.
        when 'SELE'. perform line_selection_u.
        when 'REFR'. perform call_rfc_ping_wait.
                     perform smart_show_long_usr_info.
*       when 'PICT'. perform build_document using sel_bname.
        when 'VISI'. perform toggle_visible using sel_bname.
        when 'CONN'. perform toggle_badres.
        when 'ALTP'. perform toggle_altpict.
        when 'ALTB'. perform toggle_altbkgr.
        when 'SETB'. perform change_background.
        when 'SIZE'. perform toggle_resize.
        when 'DCKL'. perform dock_dc using 1.
        when 'DCKT'. perform dock_dc using 2.
        when 'DCKB'. perform dock_dc using 4.
        when 'DCKR'. perform dock_dc using 8.
        when 'SEND'. perform send_popup_to_user using p_mandt sel_bname.
        when 'PREV'. perform another_user using -1 ' '.
        when 'NEXT'. perform another_user using  1 ' '.
        when 'PREA'. perform another_user using -1 'X'.
        when 'NEXA'. perform another_user using  1 'X'.
        when 'SM50'. perform call_sm50.
        when 'SM04'. perform call_sm04.
        when 'SM12'. perform call_sm12.
        when 'SM13'. perform call_sm13.
        when 'SM02'. perform call_sm02.
        when 'OS01'. perform call_os01.
*       when 'BUF1'
*         or 'BUF2'
*         or 'BUF3'
*         or 'BUF4'
*                  . move sy-ucomm+3(1) to new_buffering.
*                    perform call_rfc_ping_wait.
*                    perform smart_show_long_usr_info.
        when 'STAT'. perform stat_records   using         sel_bname.
*--------------------for SAP R/3 Release 4.6C
        when 'TRAC'. perform user_trace     using         sel_bname.
*--------------------for SAP R/3 Enterprise (4.7)
*       when 'TRAC'. perform user_trace_47  using p_mandt sel_bname.
        when 'FAIL'. perform show_last_fail using p_mandt sel_bname.
        when 'FAIH'. perform show_fail_hist using p_mandt sel_bname.
        when 'REQU'. perform fill_request   using p_mandt sel_bname.
        when 'OBJT'. perform show_object.
        when 'OUSR'. perform where_used_in_users.
        when 'OAGR'. perform where_used_in_roles.
        when 'UAGR'. perform show_roles.
        when 'AUTH'. notify_about_client.
                     perform display_user_auths using sel_bname.
        when 'AUTO'. perform toggle_flag changing p_refr.
                     perform report_p_refr_status.
        when 'AREF'. perform toggle_aref.
        when 'AGRF'. perform toggle_agrf.
        when 'PWDI'. perform toggle_pwdinfo.
        when 'PATH'. perform change_path_to_photos.
        when 'EXTE'. perform change_extension.
        when 'LANG'. perform cmd_next_language_u.
        when 'MLOG'. perform show_log.
        when 'DLOG'. perform clear_log.
        when 'DOCS'. perform show_documentation.
*       when 'HTML'. perform write_to_html.
*-------Does not work properly on SAP Release > 4.6B!
        when 'SLON'. perform create_slave_selected.
        when 'SLOF'. perform remove_slave_selected.
        when 'CANCEL'. set_fcode 'BACK'. "set screen 0. leave screen.
        when others. perform other_okcode.
      endcase.
    when 'SESS'.
      case sy-ucomm.
        when 'SELE'. perform line_selection_s.
        when 'OKAY'. perform process_input_s.
        when 'REFR'. perform cmd_refresh_list_s.
        when 'SRTA'. sort_flg = 'X'. perform sort_list_s.
        when 'SRTD'. sort_flg = ' '. perform sort_list_s.
        when 'SELB'. perform select_block_s.
        when 'SELI'. perform cmd_invert_s.
        when 'SEND'. perform send_popup_s.
        when 'SENL'. perform log_failed_alv using ' '.
        when 'WAST'. perform toggle_flag changing waste_flg.
                     perform print_table_s.
        when 'TALL'. if expert = 'X'.
                       sessions_toggle_flag f_th_all.
                     endif.
        when 'NOIP'. sessions_toggle_flag p_no_ip.
        when 'MTCH'. sessions_toggle_flag p_match.
        when 'WIDE'. perform toggle_wide.
        when 'SM04'. perform call_sm04.
        when 'SM12'. perform call_sm12.
        when 'SM13'. perform call_sm13.
        when 'DELE'. perform kick_out_user.
        when 'AUTO'. perform toggle_flag changing p_refr.
        when 'AREF'. perform toggle_aref.
        when 'AGRF'. perform toggle_agrf.
        when 'MEMD'. perform toggle_flag changing p_detail.
                     perform simulate_sapgui_update_ex.
        when 'LANG'. perform cmd_next_language_s.
        when 'REMS'. perform goto_remote_server.
        when 'MLOG'. perform show_log.
        when 'DLOG'. perform clear_log.
        when 'DOCS'. perform show_documentation.
        when 'VISI'. perform toggle_visible using last_html_bname.
        when 'CONN'. perform toggle_badres.
        when 'ALTP'. perform toggle_altpict.
        when 'ALTB'. perform toggle_altbkgr.
        when 'SETB'. perform change_background.
        when 'SIZE'. perform toggle_resize.
*       when 'HTML'. perform write_to_html.
        when 'EXCE'. perform export_to_excel_sess.
        when 'CLPB'. perform export_to_clipboard tables it41s using ' '.
        when 'CTLC'. perform export_to_clipboard_sess.
        when 'CTLV'. perform mark_from_clipboard_sess.
        when 'CANCEL'. set_fcode 'BACK'. "set screen 0. leave screen.
        when others. perform other_okcode.
      endcase.
  endcase.
endform. "AT_USER_COMMAND
*-----------------------------------------------------------------------
form at_main_cancel.
  confirm_step
    'Y'
    'Do you want to leave this screen'(423)
    'Press Yes to confirm'(424)
    'Navigation confirmation'(886)
     .
  if ans = 'J'.
*   set_fcode 'BACK'.
    set screen 0. leave screen.
  else.
    perform action_cancelled.
  endif.
endform. "AT_MAIN_CANCEL
*-----------------------------------------------------------------------
data wa_aref like sy-lisel.
constants:
  aref_stop(2)              value
                                  '2O' " icon_system_cancel
*                                 '3U' " icon_breakpoint
*                                 '7K' " icon_oo_event
*                                 'P7' " icon_rating_neutral
*                                 'DF' " icon_complete
*                                 '5R' " icon_workflow_indefinite_step
, aref_start like aref_stop value
                                  '2K' " icon_system_okay
*                                 '9R' " icon_time_ina
.
define modify_icon.
* read   line &1 index &2 field value &3 into wa_aref.
* modify line &1 index &2 field value &3 from &4.

  read   line &1 index &2 line value into wa_aref.
  replace &3 with &4 into wa_aref.
  modify line &1 index &2 line value from wa_aref.
end-of-definition. "MODIFY_ICON
*-----------------------------------------------------------------------
define aref_start_stop.
  modify_icon &1 &2 aref_start aref_stop.
end-of-definition. "AREF_START_STOP
*-----------------------------------------------------------------------
define aref_stop_start.
  modify_icon &1 &2 aref_stop aref_start.
end-of-definition. "AREF_STOP_START
*-----------------------------------------------------------------------
form toggle_aref.
*-Switch flag
  perform toggle_flag changing p_aref.

*-Replace corresponding icons on parent list(s)
  case sy-pfkey.
    when 'SESS'. if p_aref = 'X'. aref_start_stop 1 0.
                            else. aref_stop_start 1 0. endif.

    when 'USER'. if p_aref = 'X'.
                   case sy-lsind.
                     when 2. aref_start_stop 1 0.
                     when 3. aref_start_stop 1 0.
                             aref_start_stop 2 1.
                     when others.
                   endcase.
                 else.
                   case sy-lsind.
                     when 2. aref_stop_start 1 0.
                     when 3. aref_stop_start 1 0.
                             aref_stop_start 2 1.
                     when others.
                   endcase.
                 endif.
    when others.
  endcase.

*-Async. RFC ping
  if p_aref = 'X'.
    perform call_rfc_ping_wait.
* elseif not busy_cnt is initial.
*   wait until busy_cnt eq 0 up to arfc_secs seconds.
*   clear busy_cnt.
  endif.
endform. "TOGGLE_AREF
*-----------------------------------------------------------------------
form toggle_agrf.
  perform toggle_flag changing f_ar.
  perform simulate_sapgui_update.
endform. "TOGGLE_AGRF
*-----------------------------------------------------------------------
form toggle_keep.
  perform toggle_flag changing f_keep.
  perform set_color_for_header.
  perform print_table.
endform. "TOGGLE_KEEP
*-----------------------------------------------------------------------
form toggle_pwdinfo.
  perform toggle_flag changing f_pwdinfo.
  perform simulate_sapgui_update.
endform. "TOGGLE_PWDINFO
*-----------------------------------------------------------------------
form set_chck_icon.
  if f_chkaddr = 'X'.
    chck_icon =  icon_presence.
    q_chck    = 'Check for missing addresses is ON'(322).
  else.
    chck_icon =  icon_absence.
    q_chck    = 'Check for missing addresses is OFF'(323).
  endif.
endform. "SET_CHCK_ICON
*-----------------------------------------------------------------------
form toggle_chkaddr.
  perform toggle_flag changing f_chkaddr.
  perform set_chck_icon.
endform. "TOGGLE_CHKADDR
*-----------------------------------------------------------------------
form get_tcode_text using value(v_langu) value(v_tcode)
                 changing value(v_ttext)
                          .
  clear v_ttext.
  select single ttext into v_ttext
                      from tstct
                      where sprsl = v_langu
                        and tcode = v_tcode
                            .
endform. "GET_TCODE_TEXT
*-----------------------------------------------------------------------
form get_my_attr.
* Get my own Terminal ID
  call 'ThUsrInfo'
    id 'OPCODE'              field opcode_usr_attr
    id 'TERMINAL'            field my_terminal  "Terminal name (12)
    id 'TID'                 field my_tid       "Terminal ID
*   id 'HOSTADDR'            field hostaddr
*   id 'ACT_SESSIONS'        field act_sessions
*   id 'MAX_SESSIONS'        field max_sessions
*   id 'MY_SESSION'          field my_session
*   id 'MY_INTERNAL_SESSION' field my_internal_session
*   id 'TASK_STATUS'         field task_state
    .
endform. "GET_MY_ATTR
*-----------------------------------------------------------------------
form check_function using v_func type ty_func
                 changing t_func type tt_func
                        .
  t_func-name   = v_func.
  t_func-exists = space.

  select single funcname from tfdir
                         into t_func-name
                         where funcname = v_func
                               .
  if sy-subrc = 0.
*---Custom function exists
    t_func-exists = 'X'.
  endif.
endform. "CHECK_FUNCTION
*-----------------------------------------------------------------------
form set_transaction using sap_tcode type ty_tcode
                  changing usr_tcode type ty_tcode
                           .
* select count( * ) from tstc where tcode = usr_tcode.
  select single tcode from tstc into usr_tcode where tcode = usr_tcode.
  if sy-subrc <> 0.
*---Custom transaction does not exist, we will use standard (or dummy)
    usr_tcode = sap_tcode.
  endif.
endform. "SET_TRANSACTION
*-----------------------------------------------------------------------
*-Get host IP address
*--------------------------------------------------*
*  move sy-host to host_ip.
*  call function 'RFC_HOST_TO_IP'
*       exporting
*         rfchost                     = host_ip
*       importing
*         rfcip                       = host_ip
*       exceptions
*         host_to_ip_conversion_error = 1
*         .
*  if sy-subrc <> 0.
*    host_ip = 'IP not detected'(859).
*  endif.
*--------------------------------------------------*
* See source in FM RFCDES_DISPLAY (form HOST_TO_IP)
form get_host_ip using value(host)
              changing ip
*                      subrc
                       .
  data:
    host2(2)
* , l_ip(64) "No IP translation
  .
  ip = host.
* subrc = 0.
  if host     = space. exit. endif.

  host2 = host.
  if host2    = '%%'.  exit. endif.  "SAPGUI
  if host2(1) = '/'.   exit. endif.  "SAProuter

  call 'RFCControl'
    id 'CODE'     field 'A'
    id 'IP'       field  ip   "l_ip
    id 'HOSTNAME' field  host
      .
  if sy-subrc <> 0.
*--'Host name & unknown'
*   message s010(sr) with host.
    ip = 'IP not detected'(859).
  endif.
* subrc = sy-subrc.
endform. "GET_HOST_IP
*-----------------------------------------------------------------------
form get_user_name using v_mandt      like sy-mandt
                         v_bname      like usr21-bname
                changing v_name_first like adrp-name_first
                         v_name_last  like adrp-name_last
                         .
  clear: v_name_first, v_name_last.
* select single a~name_first
*               a~name_last
*               from (                 usr21 as u
*                      left outer join adrp  as a
*                      on u~mandt      = a~client     and
*                         u~persnumber = a~persnumber and
*                         a~date_from  = c_date1      and
*                         a~nation     = langver )
*               client specified
*               into (v_name_first, v_name_last)
*               where u~mandt     = v_mandt
*                 and u~bname     = v_bname
*                 and a~date_from = c_date1
*                 and a~date_to   = c_date2
*                 and a~nation    = langver

  select single a~name_first
                a~name_last
                from (            usr21 as u
                       inner join adrp  as a
                       on u~mandt      = a~client     and
                          u~persnumber = a~persnumber )
                client specified
                into (v_name_first, v_name_last)
                where u~mandt     = v_mandt
                  and u~bname     = v_bname
                  and a~date_from = c_date1
*                 and a~date_to   = c_date2
                  and a~nation    = langver
                      .
endform. "GET_USER_NAME
*-----------------------------------------------------------------------
form cmd_expand_squeeze.
  perform toggle_flag changing p_expand.
  perform depend_expand.
  perform print_list_as_is.
endform. "CMD_EXPAND_SQUEEZE
*-----------------------------------------------------------------------
form cmd_cpynam.
  perform toggle_flag changing p_cpynam.
  if p_cpynam is initial.
    app_log_z2_1 '030' text-391.
    message s030
       with 'Copy username when doubleclick surname is OFF'(391).
  else.
    app_log_z2_1 '030' text-390.
    message s030
       with 'Copy username when doubleclick surname is ON'(390).
  endif.
  perform depend_cpynam.
  perform print_list_as_is.
endform. "CMD_CPYNAM
*-----------------------------------------------------------------------
form cmd_next_language_m.
  perform next_language.
  perform print_table.
endform. "CMD_NEXT_LANGUAGE_M
*-----------------------------------------------------------------------
form cmd_next_language_u.
  perform next_language.
  perform smart_show_long_usr_info.
endform. "CMD_NEXT_LANGUAGE_U
*-----------------------------------------------------------------------
form cmd_next_language_s.
  perform next_language.
  perform print_table_s. "repeat output only
endform. "CMD_NEXT_LANGUAGE_S
*-----------------------------------------------------------------------
form next_language.
  data:
    lang_text like t002t-sptxt
  , tmp(30)
  , la(2)
  .
*-For two-language environment it may be hard-coded, e.g.:
* if langu = 'E'. langu = 'R'. else. langu = 'E'. endif.

*-Prevent ABAP Dump
  if lang_len is initial or cant_switch_lang = 'X'.
    app_log_z2_0 '095'.
*--'Cannot switch language'
    message s095.
  else.
*---For multi-language environment it must be evaluated:
    lang_pos = ( lang_pos + 1 ) mod lang_len.
    langu = inst_lang+lang_pos(1).

    set language langu.
*   perform simulate_sapgui_update.
    clear lang_text.
    select single sptxt from t002t
                        into lang_text
                        where spras = sy-langu
                          and sprsl =    langu
                              .
    write langu to la.
    concatenate la lang_text into tmp separated by ' - '.
*   app_log_z2_1 '060' langu.
    app_log_z2_1 '060' tmp.
*--'Set language &'
*   message s060 with langu.
    message s060 with tmp.
  endif.
endform. "NEXT_LANGUAGE
*-----------------------------------------------------------------------
form issue_run_message using value(v_object) value(f_prog).
  data tmp(70).
  if f_prog = 'X'.
    concatenate 'Submit'(301)              v_object dot3
           into  tmp
                 separated by space
                 .
  else.
    concatenate 'Calling transaction'(666) v_object dot3
           into  tmp
                 separated by space
                 .
  endif.

  condense tmp.
  progress_ind tmp.
endform. "ISSUE_RUN_MESSAGE
*-----------------------------------------------------------------------
form issue_select.
  progress_ind 'Selecting...'(036).
endform. "ISSUE_SELECT
*-----------------------------------------------------------------------
form confirm_program_run using v_repid like syst-cprog.
*-'Run the program' + <report name> + '?'
  concatenate text-304 v_repid '?' into pop_txt separated by space.
  confirm_step 'Y'
               'This takes a several minutes'(302)
                pop_txt
               'Start program'(303)
                .
endform. "CONFIRM_PROGRAM_RUN
*-----------------------------------------------------------------------
form warning_on_expert.
  app_log_z2_0 '020'.
*-'You're authorized as EXPERT. Additional functions are allowed'
  message s020.
endform. "WARNING_ON_EXPERT
*-----------------------------------------------------------------------
form auth_check using l_fld changing l_flg.
  authority-check object obj_sysadm
    id obj_sysadm field l_fld
    .
  if sy-subrc = 0. l_flg = 'X'. else. clear l_flg. endif.
endform. "AUTH_CHECK
*-----------------------------------------------------------------------
form write_syslog using value(v_text).
*-Write message to SYSLOG
* See source in rep. RSUSR003
* SE92 -> E0 3: Program &8 Reports &8&8&8
  data:
    begin of data_area
  ,   program(8)
  ,   text(24)
  , end   of data_area
  .
  data_area-program = sy-repid.
  data_area-text    = v_text.
  call function 'RSLG_WRITE_SYSLOG_ENTRY'
       exporting
         sl_message_area    = 'E0'
         sl_message_subid   = '3'
         data_area          =  data_area
       exceptions
         data_missing       =  1
         data_words_problem =  2
         other_problem      =  3
         pre_params_problem =  4
         others             =  5
         .
  if sy-subrc <> 0.
  endif.
endform. "WRITE_SYSLOG
*-----------------------------------------------------------------------
form check_authorization.
*----------------------------------------
define check_for_expert_mode.
*-Here used slightly protected password
*                     (sure, any developer can recover it easily)
  data:
    v_scramble(10)
  , z      like sy-uzeit
  .
  constants
    c_hash like v_scramble value
*---hash value for FM 'DP_SCRAMBLE_STRING' (SAP R/3 Release 4.6C)
*                                '93CD1F31F8'
*---hash value for FM    'SCRAMBLE_STRING' (SAP R/3 Release 4.6C)
                                 '82F8094244'
*---hash value for FM    'SCRAMBLE_STRING' (SAP Solution Manager)
*                                '82BD0E1741'
*---hash value for FM    'SCRAMBLE_STRING' (SAP BW, SAP ERP 2005)
*                                'C6F94B5203'
  .
  move sy-uzeit to z.
  move p_pwd+0(5) to v_scramble.
  translate v_scramble to upper case.

*-for SAP R/3 Release 4.6C
* call function 'DP_SCRAMBLE_STRING'
*      changing
*        password = v_scramble
*        .
*-for SAP R/3 4.6C and NW2004S Basis 7.00
  call function 'SCRAMBLE_STRING'
       exporting
         source = v_scramble
*        key    = 26101957
       importing
         target = v_scramble
         .
  if ( v_scramble = c_hash ) and ( p_pwd+5(3) = z+0(3) ).
    move 'X' to: expert, f_cmd_showimpm, f_chkaddr, p_cpynam.
    perform depend_cpynam.
*   hd1 = col_positive. "<-- Moved to SET_COLOR_FOR_HEADER
*---Write message about successful start in EXPERT mode to SYSLOG
*   perform write_syslog using 'Started in EXPERT mode  '(905).
    perform warning_on_expert.
  else.
    clear expert.
*   hd1 = col_heading.  "<-- Moved to SET_COLOR_FOR_HEADER
*---Write message about successful start to SYSLOG
*   perform write_syslog using 'Start successful        '(904).
  endif.
end-of-definition. "CHECK_FOR_EXPERT_MODE
*----------------------------------------
* A006(Z2): message number 006 type A (abort) from the message class Z2
* Types: S-Status/Success, I-Information,       E-Error,
*        W-Warning,        A-Abort transaction, X-Generate ABAP-dump
* REMEMBER! To maintain messages from class Z2 just double-click on Z2
* in the statement 'REPORT .. MESSAGE-ID Z2' at top of this report
* If you want translate messages from original language to another one
* you should use the transaction code SE63:
*                   Translation -> Short Texts -> Messages -> Messages

  if ( enable_chk1 is initial
       or sy-uname = sapstar
       or sy-uname = admin_1
       or sy-uname = admin_2
       or sy-uname = admin_3
       or sy-uname = admin_4
       or sy-uname = admin_5
       or sy-uname = admin_6
       or sy-uname = admin_7
       or sy-uname = admin_8
       or sy-uname = admin_9
       or sy-uname = power_1
       or sy-uname = power_2
       or sy-uname = power_3
       or sy-uname = power_4
       or sy-uname = power_5
       or sy-uname = power_6
       or sy-uname = power_7
       or sy-uname = power_8
*      or sy-uname = rfc_user
     ).
*--<<<---------Bypass authority-check for special users------------<<<--
    move 'X' to:
      auth_padm
    , auth_sm02
*   , auth_nadm
*   , auth_sm21
*   , auth_audd
    , auth_st0r
    .
*--<<<---------Bypass authority-check for special users------------<<<--
  else.

*   authority-check object obj_sysadm
**----Network administration (SM54,SM55,SM58,SM59)
*     id obj_sysadm field 'NADM'
**----Process administration (SM50,SM51,SM04); intercept background job
*     id obj_sysadm field 'PADM'
**----Authorization to create, change, and delete system messages
*     id obj_sysadm field 'SM02'
**----Authorization to change trace switches
*     id obj_sysadm field 'ST0M'
**----Authorization to analyze traces
*     id obj_sysadm field 'ST0R'
**----Authorization to analyze system logs
*     id obj_sysadm field 'SM21'
**----Basis audit administration
*     id obj_sysadm field 'AUDA'
**----Basis audit display authorization
*     id obj_sysadm field 'AUDD'
*     .
    authority-check object obj_usradm
      id 'CLASS' dummy
      id 'ACTVT' field '03'
      .
*---User maintenance (SU01,SU10,SU12)
*   SU01 (Maintain users)
*   SU10 (Delete/add a profile for all users)
*   SU12 (Delete all users)

*   S_USER_GRP
*   CLASS:
*   ACTVT:
*   01 Create
*   02 Change
*   03 Display
*   05 Lock, unlock
*   06 Delete
*   08 Display change documents
*   22 Add users to activity groups
*   24 Archive
*   68 Model users and assign to systems or activity groups
*   78 Assign

    if sy-subrc <> 0.
*----'No authorization for user administration'
      message a432(00).
*----'You haven't authorization for object &'
*     message a149(00) with obj_usradm.
**    message a149(00) with sy-repid.
***   message a006(z2) with obj_sysadm.           "Missing authorization
**    exit.
    endif.

*   authdet 'NADM' auth_nadm.
    authdet 'PADM' auth_padm.
    authdet 'SM02' auth_sm02.
    authdet 'ST0R' auth_st0r.
*   authdet 'SM21' auth_sm21.
*   authdet 'AUDD' auth_audd.

    if enable_chk2 = 'X' and not fm_auth_chk-exists is initial.
*---<<<---------Additional security check---------<<<---
      data subrc like sy-subrc.
      call function fm_auth_chk-name importing rc = subrc.
      if subrc <> 0.
*-------Write message about security violation to SYSLOG
        perform write_syslog using 'Security violation      '(906).
*------'Access denied: missing authorization &1'
        message a006(z2) with 'to use this program'(090).
*       exit.
      endif.
*---<<<---------Additional security check---------<<<---
    endif.
  endif.

*-Check password for EXPERT mode, if given
  check_for_expert_mode.
endform. "CHECK_AUTHORIZATION
*-----------------------------------------------------------------------
form set_color_for_header.
  if f_keep = 'X'.
    hd1    = col_group.
    hd1_in = 1.
  elseif expert = 'X'.
    hd1    = col_positive.
    hd1_in = intens.
  else.
    hd1    = col_heading.
    hd1_in = intens.
  endif.
endform. "SET_COLOR_FOR_HEADER
*-----------------------------------------------------------------------
form get_intens.
  if p_intens is initial. intens = 0. else. intens = 1. endif.
endform. "GET_INTENS
*-----------------------------------------------------------------------
form check_client using l_cli like sy-mandt.
  select single mandt from t000 into l_cli where mandt = l_cli.
endform. "CHECK_CLIENT
*-----------------------------------------------------------------------
form initial_output using value(init_flg).
  adapt_client p_mandt.
  perform check_client using p_mandt.    "Check the client
  if sy-subrc <> 0.
    app_log_00_1 '163' p_mandt.
*--'Client & is not available. Please choose an existing client'
    message s163(00) with p_mandt.
*   message s013     with p_mandt.       "Client does not exist
    exit.
  endif.
* perform refresh_list.
  if init_flg = 'X'.
    perform get_data using ' '.
    perform print_list_by_bname.
  else. perform refresh_list. endif.
endform. "INITIAL_OUTPUT
*-----------------------------------------------------------------------
form process_input_m using f_msg.    "User has entered new client value
* read line 1.                           "Set line 1 as current selected
* move sy-lisel+10(3) to new_cli.        "Read value from this line
  read line 1 field value p_mandt into new_cli
                          cmd     into new_cmd
                          .
  adapt_client new_cli.

  if new_cli <> p_mandt.                 "If new value differs with old
    perform check_client using new_cli.  "Check the client
    if sy-subrc <> 0.
      app_log_00_1 '163' new_cli.
*----'Client & is not available. Please choose an existing client'
      message w163(00) with new_cli.
*     message w013     with new_cli.     "Client does not exist
    else.
      move new_cli to p_mandt.           "Change client value
      perform fill_mandt_f.              "Refresh mandt_f
      perform refresh_list.              "Get new list
      scroll list index 1 to first page line 1. "Jump to first page
    endif.
  else.
    if not new_cmd is initial and not p_cmd is initial.
*-----Command processing disabled?
      if f_cmd_disable is initial.
*-------Command mode or Search mode?
        if f_cmd_mode is initial.
          case new_cmd+0(1).
            when cmd_tag. shift new_cmd left.
                          perform process_command.
            when others.  perform search_entry.
          endcase.
        else.
*---------Treat input as a command
          perform process_command.
        endif.
      else.
*-------Treat input as a search pattern
        perform search_entry.
      endif.
    elseif not p_cmd is initial and f_msg = 'X'.
      app_log_z2_1 '030' text-398.
      message s030 with 'Command line is empty'(398).
    endif.
  endif.
endform. "PROCESS_INPUT_M
*-----------------------------------------------------------------------
define command_processed.
* clear cmd.
  app_log_z2_0 '100'.
*'Command processed'
  message s100.
end-of-definition. "COMMAND_PROCESSED
*-----------------------------------------------------------------------
form toggle_showimpm.
  perform toggle_flag changing f_cmd_showimpm.
  perform print_table.
endform. "TOGGLE_SHOWIMPM
*-----------------------------------------------------------------------
form disable_commands.
  f_cmd_disable = 'X'.
* command_processed.
  app_log_z2_1 '030' text-260.
  message s030
    with 'Commands disabled. Type CMDD in OK-code to enable.'(260).
  perform modify_mode_icon.
endform. "DISABLE_COMMANDS
*-----------------------------------------------------------------------
form cmd_mark_mode.
*-Always do cleanup before switch mode
  perform set_new_search.

*-Raise F_CMD_AUTOSCAN
  f_cmd_autoscan = 'X'.
*-Clear F_CMD_AUTOCROP
  f_cmd_autocrop = ' '.
*-Clear F_CMD_MODE
  f_cmd_mode     = ' '.

  perform modify_mode_icon.
  app_log_z2_0 '110'.
*-'Mark mode activated'
  message s110.
endform. "CMD_MARK_MODE
*-----------------------------------------------------------------------
form cmd_filter_mode.
*-Always do cleanup before switch mode
  perform set_new_search.

*-Raise F_CMD_AUTOSCAN
  f_cmd_autoscan = 'X'.
*-Raise F_CMD_AUTOCROP
  f_cmd_autocrop = 'X'.
*-Clear F_CMD_MODE
  f_cmd_mode     = ' '.

  perform modify_mode_icon.
  app_log_z2_0 '111'.
*-'Filter mode activated'
  message s111.
endform. "CMD_FILTER_MODE
*-----------------------------------------------------------------------
form cmd_search_mode.
*-Always do cleanup before switch mode
  perform set_new_search.

*-Clear F_CMD_AUTOSCAN
  f_cmd_autoscan = ' '.
*-Clear F_CMD_AUTOCROP
  f_cmd_autocrop = ' '.
*-Clear F_CMD_MODE
  f_cmd_mode     = ' '.

  perform modify_mode_icon.
  app_log_z2_0 '112'.
*-'Search mode activated'
  message s112.
endform. "CMD_SEARCH_MODE
*-----------------------------------------------------------------------
form cmd_command_mode.
*-Always do cleanup before switch mode
  perform set_new_search.

*-Raise F_CMD_MODE
  f_cmd_mode     = 'X'.

  perform modify_mode_icon.
  app_log_z2_0 '113'.
*-'Command mode activated'
  message s113.
endform. "CMD_COMMAND_MODE
*-----------------------------------------------------------------------
form toggle_range.
  perform toggle_flag changing f_cmd_range.
  perform depend_range using 'X'.
endform. "TOGGLE_RANGE
*-----------------------------------------------------------------------
form depend_range using f_report.
*-Always do cleanup before switch mode or search area range
  perform set_new_search.

  if f_cmd_range = ' '.
    area_icon =  icon_bw_ra_setting_active.
    q_area    = 'Set narrow search area'(338).
    if f_report = 'X'.
      perform print_table.
      app_log_z2_0 '114'.
*----'Wide search area was set'
      message s114.
    endif.
  else.
    area_icon =  icon_bw_ra_setting_inactive.
    q_area    = 'Set wide search area'(339).
    if f_report = 'X'.
      perform print_table.
      app_log_z2_0 '115'.
*----'Narrow search area was set'
      message s115.
    endif.
  endif.
endform. "DEPEND_RANGE
*-----------------------------------------------------------------------
form process_command.
  data:
    v_cmd      like new_cmd
  , cmd_msg_txt(70)
  , cmd_help(5) value 'HELP'
  , tmp_num    like p_period
  , len_tmp    type i
  , len_period type i
  .
  define repl_help.
    replace amp with cmd_help into cmd_msg_txt. condense cmd_msg_txt.
  end-of-definition. "REPL_HELP

  v_cmd = new_cmd.

*-Always remove leading spaces before tag removal
  shift v_cmd left deleting leading space.

*-Remove leading tag if present
  if v_cmd+0(1) = cmd_tag.
    shift v_cmd left.
  endif.

*-Always remove leading spaces after tag removal
  shift v_cmd left deleting leading space.

*-Add command tag if we aren't in command mode
  if f_cmd_disable = 'X' or f_cmd_mode is initial.
    concatenate cmd_tag cmd_help into cmd_help.
  endif.

*-Empty command
  if new_cmd is initial.
    cmd_msg_txt = 'Command expected after &. Type & for details.'(197).
    replace amp with cmd_tag into cmd_msg_txt.
    repl_help.
    app_log_z2_1 '030' cmd_msg_txt.
    message w030 with cmd_msg_txt.
  endif.

  translate v_cmd to upper case.
  case v_cmd.
*---Display short help on commands
    when 'HELP'
      or 'H'
         .       perform display_commands.

*---Switch to MARK mode
    when 'MARK'
      or 'M'
         .       perform cmd_mark_mode.

*---Switch to FILTER mode
    when 'FILTER'
      or 'F'
         .       perform cmd_filter_mode.

*---Switch to SEARCH mode
    when 'SEARCH'
      or 'S'
         .       perform cmd_search_mode.

*---Switch to COMMAND mode
    when 'CMD'
      or 'C'
         .
         .       perform cmd_command_mode.

*---Toggle COMMAND mode ON/OFF
    when 'CMD!'
         .       perform toggle_cmd_mode.
                 command_processed.

*---Exit from COMMAND mode
    when 'EXIT'
*     or 'X'
         .
*----------------Clear F_CMD_MODE
                 f_cmd_mode     = ' '.

                 perform modify_mode_icon.
                 command_processed.

*---Disable command processing
    when 'DISABLE'
      or 'CMD-'
         .
                 perform disable_commands.

*---Hide command line
    when 'HIDE'
      or 'CMDL'
         .       perform toggle_cmdl.
                 command_processed.

*---Mark all users
    when 'ALL'
         .       perform cmd_select_all.

*---Unmark all users
    when 'NONE'
         .       perform cmd_select_none.

*---Invert selection
    when 'INV'
         .       perform cmd_invert.

*---Select users with last registration date <= threshold
    when 'OLD'
         .       perform cmd_select_old.

*---Select users with creation date > threshold
    when 'NEW'
         .       perform cmd_select_new.

*---Report threshold date
    when 'DATE'
         .       perform report_threshold_date.

*---Get and set threshold date
    when 'SETDATE'
         .       perform set_threshold_date.

*---Select users with unused logins
    when 'NOTUSED'
         .       perform cmd_select_not_used.

*---Select users with incorrect logons
    when 'ERR'
         .       perform cmd_select_yellow.

*---Select locked users
    when 'LOCKED'
         .       perform cmd_select_red.

*---Select users locked by administrator
    when 'LOCKEDADM'
         .       perform cmd_select_red_adm.

*---Select users locked by incorrect logon
    when 'LOCKEDERR'
         .       perform cmd_select_red_err.

*---Select users with reference user
    when 'LINKED'
      or 'LINK'
         .       perform cmd_select_with_refuser.

*---Select users with empty security group (USR02-CLASS)
    when 'NOCLASS'
      or 'NOSECU'
         .       perform cmd_select_noclass.

*---Select users without address data
    when 'NOADDR'
         .       perform cmd_select_noaddr.

*---Select all users with type other than type 'A'
    when 'NONDIA'
         .       perform cmd_select_nondia.

*---Set search area range to WIDE
    when 'WIDE'
      or 'W'
         .       f_cmd_range = ' '.
                 perform depend_range using 'X'.

*---Set search area range to NARROW
    when 'NARROW'
      or 'N'
         .       f_cmd_range = 'X'.
                 perform depend_range using 'X'.

*---Toggle search area range: WIDE <-> NARROW
    when 'RANGE'
      or 'R'
      or 'CMDR'
         .       perform toggle_range.

*---Toggle AUTOSCAN option
    when 'AUTOSCAN'
      or 'CMDA'
         .       perform toggle_cmd_autoscan.
                 command_processed.

*---Toggle AUTOCROP option
    when 'AUTOCROP'
      or 'CMDC'
         .       perform toggle_cmd_autocrop.
                 command_processed.

*---Toggle import mode indicator ON/OFF
    when 'SHOWMODE'
      or 'SHMO'
         .       perform toggle_showimpm.
*                command_processed.

*---Highlight entry found
    when 'HIGHLIGHT'
      or 'CMDH'
         .       perform toggle_flag changing f_cmd_highlight.
                 command_processed.

*---Toggle scroll to entry found
    when 'SCROLL'
      or 'CMDS'
         .       perform toggle_flag changing f_cmd_scroll.
                 command_processed.

*---Toggle Paste and Process mode ON/OFF
    when 'FASTFIND'
      or 'CMDF'
         .       perform toggle_flag changing f_cmd_fastfind.
                 command_processed.

*---Exclude marked users from view
    when 'EXCLUDE'
      or 'EXCL'
         .       perform exclude_from_list.

*---Crop view (exclude non-marked users from view)
    when 'CROP'
         .       perform crop_list.

*---Force Refresh
    when 'REFRESH!'
      or 'REFR!'
      or 'UPDA'
         .       perform cmd_refresh_list_force.

*---Refresh
    when 'REFRESH'
      or 'REFR'
         .       perform cmd_refresh_list.

*---Refresh but stay filtered
    when 'FRESH'
      or 'TOUCH'
         .       perform cmd_fresh_list.

*---Toggle hold entries on refresh ON/OFF
    when 'KEEP'
      or 'K'
         .       perform toggle_keep.

*---Switch language (partially)
    when 'LANG'
         .       perform cmd_next_language_m.

*---Turn ABAP-debugger ON
    when 'DEBUG'
         .       perform cmd_debug.

*---Toggle F_CHKADDR ON/OFF
    when 'CHCK'
         .       perform toggle_chkaddr.
                 perform print_table.
                 command_processed.

*---Expand/Collapse TEL_NUMBER field
    when 'EXPA'
         .       perform cmd_expand_squeeze.
*                command_processed.

*---Export to Excel
    when 'EXCEL'
         .       perform export_to_excel_main.

*---Copy marked entries (BNAME field only) to clipboard
    when 'CTLC'
      or 'COPY'
      or 'EXP'
         .       perform export_to_clipboard_main.

*---Mark entries from clipboard
    when 'CTLV'
      or 'IMP'
         .       perform mark_from_clipboard.

*---Number or Unknown command?
    when others.
                 if v_cmd co ' 0123456789'.
                   condense v_cmd no-gaps.
                   describe field p_period output-length len_period.
                   len_tmp = strlen( v_cmd ).
                   if len_tmp > len_period.
                     app_log_z2_0 '101'.
*-------------------'Entered value is too big'
                     message s101.
                   else.
                     move v_cmd to tmp_num.
                     perform set_period_ex using tmp_num.
                   endif.
                 else.
                   cmd_msg_txt =
                    '- unknown command. Type & for details.'(190).
                   repl_help.
                   app_log_z2_2 '031' new_cmd cmd_msg_txt.
                   message w031 with new_cmd cmd_msg_txt.
                 endif.

  endcase.
endform. "PROCESS_COMMAND
*-----------------------------------------------------------------------
form display_commands.
  data:
    it_cmd type standard table of abapsource
  , wa like line of it_cmd.
  .
  define ahelp.
    append &1 to it_cmd.
  end-of-definition. "APP_CMD_HELP

  wa = '* Out of command mode prefix & is required for commands'(271).
  replace amp with cmd_tag into wa.

  ahelp  wa.
  ahelp  space.
  ahelp '******************* GENERAL COMMANDS *******************'(267).
  ahelp 'HELP      - this help'(192).
  ahelp 'MARK      - switch to mark mode'(264).
  ahelp 'FILTER    - switch to filter mode'(265).
  ahelp 'SEARCH    - switch to search mode'(266).
  ahelp 'CMD       - switch to command mode'(274).
  ahelp 'EXIT      - quit command mode'(273).
  ahelp 'DISABLE   - disable commands'(258).
  ahelp 'WIDE      - set wide scan range: BNAME .. ROOMNUMBER'(268).
  ahelp 'NARROW    - set narrow scan range: BNAME .. NAME_LAST'(272).
  ahelp 'SHOWMODE  - import mode indicator ON/OFF'(255).
  ahelp  space.
  ahelp '******************* SELECTION COMMANDS *****************'(284).
  ahelp 'ALL       - mark all users'(317).
  ahelp 'NONE      - unmark all users'(318).
  ahelp 'INV       - invert selection'(319).
  ahelp 'EXP       - copy marked users to clipboard'(328).
  ahelp 'IMP       - mark users from clipboard'(329).

  wa =  'OLD       - users with reg. date <= &'(286).
  replace amp with s_datum into wa.
  ahelp wa.

  wa =  'NEW       - users created from &'(287).
  replace amp with s_datum into wa.
  ahelp wa.

  ahelp 'ERR       - users with incorrect logons'(288).
  ahelp 'LOCKED    - locked users'(291).
  ahelp 'LOCKEDADM - users locked by administrator'(292).
  ahelp 'LOCKEDERR - users locked by incorrect logons'(293).
  ahelp 'LINKED    - users with reference users'(316).
  ahelp 'NOTUSED   - unused logins'(297).
  ahelp 'NOADDR    - users without address data (if enabled)'(289).
  ahelp 'NOCLASS   - users without security group (USR02-CLASS)'(290).
* ahelp 'NOMAIL    - users with empty e-mail'().
  ahelp 'NONDIA    - users with type other than A'(307).
  ahelp  space.
  ahelp '****************** PROCESSING COMMANDS *****************'(285).
  ahelp 'REFR      - refresh list'(294).
  ahelp 'EXCL      - exclude marked entries from list'(295).
  ahelp 'CROP      - crop list (display marked entries only)'(296).
  ahelp 'DATE      - report threshold date'(300).
  ahelp 'SETDATE   - set threshold date'(312).
  ahelp 'LANG      - switch language'(308).
  ahelp 'DEBUG     - turn ABAP-debugger ON'(320).
  ahelp 'EXCEL     - export data to Microsoft Excel'(340).
  ahelp  space.
  ahelp '***************** SOME SPECIAL SWITCHES ****************'(269).
  ahelp 'FASTFIND  - paste and search immediately ON/OFF'(230).
  ahelp 'HIGHLIGHT - highligh option ON/OFF'(194).
  ahelp 'SCROLL    - scroll list to entry found ON/OFF'(196).
  ahelp 'RANGE     - toggle search range: WIDE/NARROW'(195).
  ahelp 'AUTOSCAN  - autoscan option ON/OFF'(262).
  ahelp 'AUTOCROP  - autocrop option ON/OFF'(263).
  ahelp 'KEEP      - toggle hold entries option ON/OFF'(313).
  ahelp 'CMD!      - switch between command mode/search mode'(259).
  ahelp 'HIDE      - hide command line'(193).

  editor-call for it_cmd title 'List of commands'(191) display-mode.
  free it_cmd.
endform. "DISPLAY_COMMANDS
*-----------------------------------------------------------------------
form set_new_search.
  clear: syfdpos, sytabix, cnt_found. move new_cmd to old_cmd.
endform. "SET_NEW_SEARCH
*-----------------------------------------------------------------------
form search_entry.
* plunger.

  data:
    lin1        like sy-index
  , lin2        like lin1
  , target_lin  like lin1
  , list_lin    like lin1
  , fdpos_ok
  , textline(70)
  , title(40)
  , st_cnt_found(10)

*---for SAP R/3 Enterprise (4.7)
  , begin of it_search occurs 0
  ,   bname      like usr02-bname       "User logon name
  ,   name_last  like adrp-name_last    "User's surname
  ,   name_first like adrp-name_first   "User's first name
  ,   tel_number like adcp-tel_number   "Phone number
  ,   tel_numdis like adcp-tel_number   "Phone number for display
  ,   tel_extens like adcp-tel_extens   "Local phone number
  ,   function   like adcp-function     "User's description
  ,   department like adcp-department   "Department
  ,   building   like adcp-building     "Building
  ,   roomnumber like adcp-roomnumber   "Room
  , end   of it_search
  .
define check_fdpos.
*-for SAP R/3 Enterprise (4.7)
  if f_cmd_range is initial.
    fdpos_ok = 'X'.     "   itab IT_SEARCH has following structure:
  elseif sy-fdpos < 52. " |<- BNAME -->|<-NAME_LAST->|<-NAME_FIRST->|
    fdpos_ok = 'X'.     "  0.........11,12.........51,52..........91
  else.
    clear fdpos_ok.
  endif.

*-for SAP R/3 Release 4.6C
*  if f_cmd_range is initial.
**---Exclude all fields between 15 and  96 (offset in IT structure)
*    if not ( sy-fdpos between  15 and  96 ).
*      fdpos_ok = 'X'.
*    else.
*      clear fdpos_ok.
*    endif.
*  else.
**---Only allow search in fields BNAME and NAME_LAST
*    if     ( sy-fdpos between   3 and  14 ) "BNAME
*       or  ( sy-fdpos between 106 and 145 ) "NAME_LAST
*       .
*      fdpos_ok = 'X'.
*    else.
*      clear fdpos_ok.
*    endif.
*  endif.
end-of-definition. "CHECK_FDPOS

* check not expert is initial.

  if sytabix is initial or new_cmd <> old_cmd.
    perform set_new_search.
    lin1 = 1.
  else.
    lin1 = sytabix.
  endif.

*-for SAP R/3 Enterprise (4.7)
  cls it_search.
  loop at it assigning <fs>.
    it_search-bname      = <fs>-bname.       "User logon name
    it_search-name_last  = <fs>-name_last.   "User's surname
    it_search-name_first = <fs>-name_first.  "User's first name
    it_search-tel_number = <fs>-tel_number.  "Phone number
    it_search-tel_numdis = <fs>-tel_number.  "Phone number for display
    it_search-tel_extens = <fs>-tel_extens.  "Local phone number
    it_search-function   = <fs>-function.    "User's description
    it_search-department = <fs>-department.  "Department
    it_search-building   = <fs>-building.    "Building
    it_search-roomnumber = <fs>-roomnumber.  "Room
    append it_search.
  endloop.

*-for SAP R/3 Release 4.6C
* describe table it        lines lin2.

*-for SAP R/3 Enterprise (4.7)
  describe table it_search lines lin2.

  do.
*---for SAP R/3 Release 4.6C
*   search it        for new_cmd starting at lin1 ending at lin2.

*---for SAP R/3 Enterprise (4.7)
    search it_search for new_cmd starting at lin1 ending at lin2.

    case sy-subrc.
      when 0.      check_fdpos.
                   if fdpos_ok = 'X'.
                     if syfdpos = sy-fdpos and sytabix = sy-tabix.
                       lin1 = sy-tabix + 1.
                       continue.
                     endif.
                     add 1 to cnt_found.
                     syfdpos    = sy-fdpos.
                     sytabix    = sy-tabix.
                     target_lin = sy-tabix.
*--------------------Highlight line with inverse intensity
                     if f_cmd_highlight = 'X'.
                       list_lin = target_lin + head_bo.
                       read line list_lin.
                       if p_intens is initial.
                         modify line list_lin
                           line format intensified on.
                       else.
                         modify line list_lin
                           line format intensified off.
                       endif.
                     endif.
                     if f_cmd_autoscan = 'X'.
                       read table it index sytabix.
                       it-mark = 'X'.
                       modify it index sytabix.
                       modify line list_lin
                         field value 'IT-MARK' from it-mark.
                     endif.
*--------------------Scroll list
                     if f_cmd_scroll = 'X'.
                       scroll list to first page line target_lin.
                     endif.
                     app_log_z2_3 '032'
                       new_cmd text-187 sytabix.
                     message s032 with
                       new_cmd '- found at line'(187) sytabix.
                     if f_cmd_autoscan is initial.
                       exit.
                     endif.
                   else.
                     lin1 = sy-tabix + 1.
                     continue.
                   endif.
      when others. if cnt_found is initial.
*--------------------At first, clean up, then message (cause type W)
                     perform set_new_search.
                     app_log_z2_2 '031' new_cmd text-188.
                     message w031 with new_cmd '- not found'(188).
                   else.
*--------------------At first, message (cause type S), then clean up
                     app_log_z2_3
                             '032'
                             new_cmd
                             text-189
                             cnt_found
                             .
                     if f_cmd_autoscan is initial.
                       move cnt_found to st_cnt_found.
                       condense st_cnt_found.
                       concatenate  new_cmd
                                   '- no more found'(189)
                              into  textline
                                    separated by space
                                    .
                       concatenate 'No more found. Total:'(257)
                                    st_cnt_found
                              into  title
                                    separated by space
                                    .
                       call function 'WS_MSG'
                            exporting
*-----------------------------------------I-Info, A-Alert, E-Emergency
                              msg_type = 'I'
                              text     =  textline
                              titl     =  title
                              .
                       perform set_new_search.
                     else.
                       if f_cmd_autocrop = 'X'.
                         perform set_new_search.
                         perform crop_list_ex.
                         perform invert.
                         perform jump_to_first_page.
                         perform print_table.
                       else.
                         perform print_table.
                         message s032
                            with new_cmd
                                'No more found. Total:'(257)
                                 cnt_found
                                 .
                       endif.
                     endif.
                   endif.
                   exit.
    endcase.
  enddo.
endform. "SEARCH_ENTRY
*-----------------------------------------------------------------------
form process_input_s.                "User has entered new client value
  if p_match is initial or p_wide = 'X'. exit. endif.

  read current line field value mandt_f into new_cli.
  adapt_client new_cli.

  perform check_client using new_cli.  "Check the client
  if sy-subrc <> 0.
    app_log_00_1 '163' new_cli.
*--'Client & is not available. Please choose an existing client'
    message w163(00) with new_cli.
*   message w013     with new_cli.     "Client does not exist
  elseif new_cli <> mandt_f.
    mandt_f = new_cli.
    perform refresh_list_s.            "Get new list
*   scroll list index 1 to first page line 1. "Jump to first page
  endif.
endform. "PROCESS_INPUT_S
*-----------------------------------------------------------------------
form set_contrast.
* check sy-pfkey = 'MAIN'.
* if intens = 0. intens = 1. else. intens = 0. endif.
  do.
    read line sy-index.
    if sy-subrc = 0.
**----if the current line inside of a header then skip it!
*     if sy-index <= head_bo. continue. endif.
      modify current line line format intensified = intens.
    else. exit. endif.
  enddo.
endform. "SET_CONTRAST
*-----------------------------------------------------------------------
field-symbols <tel> type adcp-tel_number.
data tel_len type i.

form print_row.     "PRINTS ONE ROW OF THE LIST
  data:
    q_info1 like rsmpe_txt-quickinfo
  , q_info2 like q_info1
* , q_info3 like q_info1
* , q_info4 like q_info1
* , q_info5 like q_info1
  , st_locnt(3)           "<-- USR02-LOCNT as string
  , st_uflag(3)           "<-- USR02-UFLAG as string
  .
*-Set common format for write operators until it will be overrided
  format intensified = intens.

*-If user active, mark him with an icon like a green ball
  if not it-online is initial.
    if not p_hot is initial. format hotspot on.  endif.
    write / it-iconid as icon.
    if not p_hot is initial. format hotspot off. endif.
  elseif it-trdat is initial.
    add 1 to sum_ini.
    write
    / iusr_icon as icon
        quickinfo 'Login not yet used in this client'(152)
    .
  elseif f_chkaddr = 'X' and it-noaddr = 'X'.
    write
    / noad_icon as icon
        quickinfo 'User without address data'(270)
    .
  else.
    new-line.
    write sy-vline.
  endif.

  case it-uflag.
    when c_not_locked.
      if it-locnt = 0.
        clear q_info1.
      else.
        q_info1 = 'Incorrect logons per user: &'(082).
        move it-locnt to st_locnt.
        replace amp with st_locnt into q_info1. condense q_info1.
        add 1 to sum_err.
      endif.

    when c_locked_by_admin.
      q_info1 = 'Locked by Administrator'(915).

    when c_locked_by_global_admin.
      q_info1 = 'Locked by Global Administrator'(094).

    when c_locked_by_failed_logon.
      q_info1 = 'Locked due to incorrect logon'(916).

    when others.
      q_info1 = 'Unknown status: USR02-UFLAG = &'(095).
      move it-uflag to st_uflag.
      replace amp with st_uflag into q_info1. condense q_info1.
  endcase.

  write:
*   at 3 it-bname color = it-c_bna "nder 'User'(202)
    it-bname color = it-c_bna under 'User'(202)
      quickinfo q_info1
  , it-mark as checkbox input off hotspot "color = it-c_bna
  .
  if not it-refuser is initial
*    and sy-saprl   ge c_saprl
         .
    add 1 to sum_ref.
    concatenate 'link active ---->'(914) it-refuser
           into  q_info2
                 separated by space
                 .
    condense q_info2.

    write link_symb as symbol no-gap quickinfo q_info2.
  else. write sy-vline no-gap. endif.

  hide: it-bname, it-mark, it-refuser.

*-Restrict moveable area from here
  if p_scroll = 'X'. set left scroll-boundary. endif.

*  if it-name_last+16(24)  eq space.
*    clear q_info4.
*  else.
*    q_info4 = it-name_last.
*  endif.
*
*  if it-name_first+24(16) eq space.
*    clear q_info5.
*  else.
*    q_info5 = it-name_first.
*  endif.

  write:
    (16) it-name_last  color = it-c_nla no-gap "nder text-003
*          quickinfo q_info4
  , (24) it-name_first color = it-c_nfi no-gap "nder text-004
*          quickinfo q_info5
  , sy-vline                            no-gap
  .
  write:
    <tel>(tel_len) color = it-c_tnu no-gap quickinfo it-tel_number
  .
*  if p_expand is initial.
*    write:
*    (09) it-tel_numdis color = it-c_tnu no-gap "nder text-005
*           quickinfo it-tel_number "q_info3
*    .
*  else.
*    write:
*    (16) it-tel_number color = it-c_tnu no-gap "nder text-005
**          quickinfo it-tel_number "q_info3
*    .
*  endif.

  write:
    sy-vline                            no-gap
  , (05) it-tel_extens color = it-c_tex no-gap "nder text-006
*          quickinfo it-tel_extens
  , sy-vline                            no-gap
  , it-function        color = it-c_fun no-gap "nder text-008
  , sy-vline                            no-gap
  , it-department      color = it-c_dep no-gap "nder text-013
  , sy-vline                            no-gap
  , (07) it-building   color = it-c_bui no-gap "nder text-018
*          quickinfo it-building
  , sy-vline                            no-gap
  , (05) it-roomnumber color = it-c_roo no-gap "nder text-019
*          quickinfo it-roomnumber
  , sy-vline                            no-gap
  , it-trdat           color = it-c_trd        "nder text-900
  , it-ltime           color = it-c_lti no-gap "nder text-901
  , sy-vline                            no-gap
  , it-modbe           color = it-c_mbe        "nder text-027
  , it-modda           color = it-c_mda        "nder text-028
  , it-modti           color = it-c_mti no-gap "nder text-029
  , sy-vline                            no-gap
  , it-aname           color = it-c_ana        "nder text-829
  , it-erdat           color = it-c_erd no-gap "nder text-830
  , sy-vline
  .
endform. "PRINT_ROW
*-----------------------------------------------------------------------
form back_if_detail.           "REUSES EXISTING OUTPUT
*-If detail list level > 0 then decrease it
  if sy-lsind > 0. subtract 1 from sy-lsind. endif.
endform. "BACK_IF_DETAIL
*-----------------------------------------------------------------------
form list_return using list_idx like sy-lsind.
*-return list to previous position
  scroll list index list_idx to column sy-staco.
  scroll list index list_idx to page   sy-cpage line sy-staro.
endform. "LIST_RETURN
*-----------------------------------------------------------------------
define mac_determine_colors_s.
  if it41s-mark = 'X'.
    col_mandt_s = col_sess = mrk.
  else.
    if it41s-mandt = sy-mandt. col_mandt_s = col_normal.
                         else. col_mandt_s = col_total. endif.
    col_sess = col_normal.
  endif.
end-of-definition. "MAC_DETERMINE_COLORS_S
*-----------------------------------------------------------------------
data ps_sortind type i.

form put_ind using value(flag) value(linno) value(cl_ind).
  data sm_sortind like sym_up_triangle.

  if ps_sortind > 0.
    if sy-pfkey = 'MAIN'
*     and not expert is initial
      .
      perform set_cmdl.
*     if expert = 'X'.
        perform set_impm.
*     endif.

      skip to line head_to.
      write: at 3
        cmdl_symb as symbol
*       cmdl_icon as icon
        color col_negative inverse
        hotspot quickinfo q_cmdl
        no-gap
*     , cmdl_symb as symbol
**    , cmdl_icon as icon
*       color col_normal inverse
*       hotspot quickinfo q_cmdl
*       no-gap
      .
*     if expert = 'X'.
        if f_cmd_showimpm = 'X'.
          write: at ps_impm
*           impm_symb as symbol
            impm_icon as icon
            color col_heading  inverse
            hotspot
            quickinfo q_impm
            no-gap
            .
        endif.
*     endif.
    endif.

    if flag = 'X'. sm_sortind = sym_up_triangle.
             else. sm_sortind = sym_down_triangle. endif.

    skip to line linno.
    write at ps_sortind sm_sortind as symbol color = cl_ind inverse.
  endif.
endform. "PUT_IND
*-----------------------------------------------------------------------
form put_sort_indicator.
  if p_expand is initial.
    case sav1.
      when 'BNAME'.      ps_sortind =   3.
      when 'NAME_LAST'.  ps_sortind =  19.
      when 'NAME_FIRST'. ps_sortind =  35.
      when 'TEL_NUMBER'
        or 'TEL_NUMDIS'. ps_sortind =  60.
      when 'TEL_EXTENS'. ps_sortind =  70.
      when 'FUNCTION'.   ps_sortind =  76.
      when 'DEPARTMENT'. ps_sortind = 117.
      when 'BUILDING'.   ps_sortind = 158.
      when 'ROOMNUMBER'. ps_sortind = 166.
      when 'TRDAT'.      ps_sortind = 172.
      when 'MODBE'.      ps_sortind = 192.
      when 'MODDA'.      ps_sortind = 205.
      when 'ANAME'.      ps_sortind = 225.
      when 'ERDAT'.      ps_sortind = 238.
      when others.       clear ps_sortind.
    endcase.
  else.
    case sav1.
      when 'BNAME'.      ps_sortind =   3.
      when 'NAME_LAST'.  ps_sortind =  19.
      when 'NAME_FIRST'. ps_sortind =  35.
      when 'TEL_NUMBER'
        or 'TEL_NUMDIS'. ps_sortind =  60.
      when 'TEL_EXTENS'. ps_sortind =  77.
      when 'FUNCTION'.   ps_sortind =  83.
      when 'DEPARTMENT'. ps_sortind = 124.
      when 'BUILDING'.   ps_sortind = 165.
      when 'ROOMNUMBER'. ps_sortind = 173.
      when 'TRDAT'.      ps_sortind = 179.
      when 'MODBE'.      ps_sortind = 199.
      when 'MODDA'.      ps_sortind = 212.
      when 'ANAME'.      ps_sortind = 232.
      when 'ERDAT'.      ps_sortind = 245.
      when others.       clear ps_sortind.
    endcase.
  endif.

  perform put_ind using sav4 head_bo col_heading.
endform. "PUT_SORT_INDICATOR
*-----------------------------------------------------------------------
define ps_sortind_detail.
  if p_detail = 'X'. ps_sortind = &1.
               else. clear ps_sortind. endif.
end-of-definition. "PS_SORTIND_DETAIL
*-----------------------------------------------------------------------
form put_sort_indicator_s.
  data cl_ind type i.

  cl_ind = col_heading. "By default
  case fld.
    when 'MARK'.       ps_sortind =   2.
    when 'MANDT'.      ps_sortind =   4.
    when 'BNAME'.      ps_sortind =   8.
    when 'NAME_LAST'.  ps_sortind =  21.
    when 'NAME_FIRST'. ps_sortind =  37.
    when 'TERMINAL'.   ps_sortind =  62.
    when 'TIME'.       ps_sortind =  90.
                       if waste_flg = 'X'. cl_ind = col_negative. endif.
    when 'DIFF'.       ps_sortind =  90.
                       if waste_flg = ' '. cl_ind = col_negative. endif.
    when 'SERVER'.     ps_sortind =  99.
*-for SAP R/3 Release 4.6C
    when 'TCODE'.      ps_sortind_detail 120.
    when 'PAGE'.       ps_sortind_detail 141.
    when 'ROLL'.       ps_sortind_detail 152.
    when 'MEMSUM'.     ps_sortind_detail 163.
    when 'PRIVSUM'.    ps_sortind_detail 174.
*-for SAP R/3 Enterprise (4.7)
*   when 'TCODE'.      ps_sortind_detail 140.
*   when 'PAGE'.       ps_sortind_detail 161.
*   when 'ROLL'.       ps_sortind_detail 172.
*   when 'MEMSUM'.     ps_sortind_detail 183.
*   when 'PRIVSUM'.    ps_sortind_detail 194.
    when others.       clear ps_sortind.
  endcase.

  perform put_ind using sort_flg head_bo_s cl_ind.
endform. "PUT_SORT_INDICATOR_S
*-----------------------------------------------------------------------
form setup_colors.
*-Invariant part
  move c01 to: it-c_bna, it-c_ana, it-c_erd, it-c_trd,
               it-c_lti, it-c_mda, it-c_mti, it-c_mbe.

  if p_prn = 'X'.
*---Printer-layout
    move c01 to: it-c_nfi, it-c_nla, it-c_dep, it-c_fun,
                 it-c_bui, it-c_roo, it-c_tnu, it-c_tex.
  else.
*---Screen-layout
    move c02 to: it-c_nfi, it-c_nla.
    move c04 to: it-c_tnu, it-c_tex.
    move c06 to: it-c_dep, it-c_fun, it-c_bui, it-c_roo.
  endif.
  modify it transporting
              c_bna c_ana c_erd c_trd c_lti c_mda c_mti c_mbe
              c_nfi c_nla c_dep c_fun c_bui c_roo c_tnu c_tex
*           where c_bna <> cl_notused
            where mandt = p_mandt
                  .
  if p_prn is initial.
*---Users without address data
    if f_chkaddr = 'X'.
      move cl_noaddr to:
        it-c_bna, it-c_nfi, it-c_nla, it-c_dep,
        it-c_fun, it-c_bui, it-c_roo, it-c_tnu, it-c_tex.

      modify it transporting
                  c_bna c_nfi c_nla c_dep c_fun
                  c_bui c_roo c_tnu c_tex
                where noaddr = 'X'
                      .
    endif.

*---Locked users
    move cl_locked to it-c_bna.
    modify it transporting c_bna
              where uflag = c_locked_by_admin
                 or uflag = c_locked_by_global_admin
                 or uflag = c_locked_by_failed_logon
                    .
*---Users with unknown status
    move cl_unknown to it-c_bna.
    modify it transporting c_bna
              where uflag <> c_not_locked
                and uflag <> c_locked_by_admin
                and uflag <> c_locked_by_global_admin
                and uflag <> c_locked_by_failed_logon
                    .
*---Users with failed logons, highlight with CL_FAILED
    move cl_failed to it-c_bna.
    modify it transporting c_bna
                where c_bna = col_normal
                  and locnt > 0
                      .
*---Users with logons older than threshold
    move col_total to: it-c_trd, it-c_lti.
    modify it transporting c_trd c_lti
                where trdat <= x_datum
                      .
*---Users never been logged on
    move col_negative to: it-c_trd, it-c_lti.
    modify it transporting c_trd c_lti
                where trdat is initial
                      .
*---Marked lines
    move mrk to: it-c_bna, it-c_nfi, it-c_nla, it-c_tnu,
                 it-c_tex, it-c_dep, it-c_fun, it-c_bui, it-c_roo.
    modify it transporting
                c_bna c_nfi c_nla c_dep c_fun c_bui c_roo c_tnu c_tex
              where mark = 'X'
                    .
*---Highlighted row
    if p_point = 'X'.
      read table it with key bname = point_bname.
      if sy-subrc = 0.
        if it-mark is initial.
*---------Affected part (by mark)
          move pnt to: it-c_bna,
                       it-c_nfi, it-c_nla, it-c_dep, it-c_fun,
                       it-c_bui, it-c_roo, it-c_tnu, it-c_tex.
        endif.
*-------Invariant part of highlighted row
        move pnt to: it-c_ana, it-c_erd, it-c_trd,
                     it-c_lti, it-c_mda, it-c_mti, it-c_mbe.
        modify it index sy-tabix.
      endif.
    endif.
  endif.
endform. "SETUP_COLORS
*-----------------------------------------------------------------------
constants:
  c_top    value '1'
, c_middle value '2'
, c_bottom value '3'
.
form uline_main using value(v_level).
  data:
    line1 like line_left_middle_corner
  , line2 like line1
  .
  case v_level.
    when c_top.
      line1 = line_top_left_corner.
      line2 = line_top_right_corner.
    when c_middle.
      line1 = line_left_middle_corner.
      line2 = line_right_middle_corner.
    when c_bottom.
      line1 = line_bottom_left_corner.
      line2 = line_bottom_right_corner.
    when others.
      line1 = line_horizontal_line.
      line2 = line_horizontal_line.
  endcase.

*  if p_expand is initial.
*    uline_m = sy-linsz - 2 - 7.
*  else.
*    uline_m = sy-linsz - 2.
*  endif.

  write:
  / line1 as line     no-gap
  , sy-uline(uline_m) no-gap
  , line2 as line     no-gap
  .
endform. "ULINE_MAIN
*-----------------------------------------------------------------------
form print_table.              "PRINTS RESULTS ON THE SCREEN
* set run time analyzer on.
  perform init_block.
  perform back_if_detail.
  perform get_activity.

* progress_ind 'Output...'(037).

  describe table it lines sum_usr.
  clear: sum_lck, sum_err, sum_ref, sum_ini.
  str_act = sum_act. condense str_act.         "Get as condensed strings
  str_usr = sum_usr. condense str_usr.
  if p_mandt <> sy-mandt.                      "If client <> current
    set titlebar '000' with sy-sysid           "SID
                            p_mandt            "Client
                            str_act            "Active users
                            str_usr            "Total users
                            ind_crop           "Indicator: list cropped?
                            text-035           "SU01 cannot be called
                            slset              "Variant (selection-set)
                            .
    if expert is initial.
*-----not expert, client <> current
      set pf-status 'MAIN' excluding extab1.   "Restricted mode 1
    else.
*-----expert,     client <> current
      set pf-status 'MAIN' excluding extab2.   "Restricted mode 2
    endif.
  else.
    set titlebar '000' with sy-sysid           "SID
                            p_mandt            "Client
                            str_act            "Active users
                            str_usr            "Total users
                            ind_crop           "Indicator: list cropped?
                            slset              "Variant (selection-set)
                            .
    if expert is initial.
*-----not expert, client == current
      set pf-status 'MAIN' excluding extab3.   "Restricted mode 3
    else.
*-----expert,     client == current
      set pf-status 'MAIN'.                    "Full functionality
    endif.
  endif.

*-Count locked users
  loop at it assigning <fs>
          where uflag = c_locked_by_admin
             or uflag = c_locked_by_global_admin
             or uflag = c_locked_by_failed_logon
                .
    add 1 to sum_lck.
  endloop.

  perform setup_colors.

  if p_expand is initial.
*   write:
*     (09) it-tel_numdis color = it-c_tnu no-gap "nder text-005
*            quickinfo it-tel_number "q_info3
*   .
    assign it-tel_numdis to <tel>.
    tel_len = 9.
  else.
*   write:
*     (16) it-tel_number color = it-c_tnu no-gap "nder text-005
**           quickinfo it-tel_number "q_info3
*   .
    assign it-tel_number to <tel>.
    tel_len = 16.
  endif.

  loop at it. perform print_row. endloop.

  move sy-linno to last_ln.     "Remember number of last line in list

  perform uline_main using c_bottom.

*-Prevent horizontal scrolling for this line
  new-line no-scrolling.
  write:
  /  space
  , 'Users by selection criteria:'(009)        "hotspot
  ,  sum_usr color = foo inverse left-justified hotspot no-gap
  , 'Locked users:'(012)
  ,  sum_lck color = foo inverse left-justified hotspot no-gap
  , 'With incorrect logons:'(887)
  ,  sum_err color = foo inverse left-justified hotspot no-gap
  , 'Logical system:'(096)
  .
  if logsys is initial.
    write '[ Not Defined ]'(097) color = foo inverse.
  else.
    write      logsys            color = foo inverse.
  endif.

  skip.

*-Prevent horizontal scrolling for this line
  new-line no-scrolling.
  write:
  /  space
  , 'Date'(024)
  ,  sy-datum color = foo inverse    "Current date
  , (05) 'Time'(032)
  ,  sy-uzeit color = foo inverse    "Current time
  , (14) 'Completed by'(023)
  ,  sy-uname color = foo inverse    "Current user
  .
  if sy-batch is initial.            "OLD VARIANT: if sy-tcode <> space.
    write:
      (11) 'Transaction'(025)
    ,  sy-tcode color = foo inverse  "Transaction
    .
  else.
    write
      (13) 'in background'(026)      "Background processing
    .
  endif.

  write:
    (06) 'Report'(015)
  ,  sy-repid color = foo inverse    "Report name
       quickinfo q_info_prog
  .
  perform write_sp_info.
  perform list_return using 1.       "Return to previous position

* set run time analyzer off.
endform. "PRINT_TABLE
*-----------------------------------------------------------------------
data:
  ps_sp1  type i
, ps_sp2  type i
, ps_sp3  type i
, ps_sp4  type i
, max_sp1 type i
, max_sp2 type i
, max_sp3 type i
, max_sp4 type i
, u_sp    type i
, spam_vers like spam_fpdef-formatted
.
form get_sp_info.
  constants spacing type i value 2.
  data:
    len_sp1 type i
  , len_sp2 type i
  , len_sp3 type i
  , len_sp4 type i
  .
  define grow.
    &2 = strlen( &1 ).
    if &2 > &3. &3 = &2. endif.
  end-of-definition. "GROW

*-Get version of installed components
  call function 'OCS_GET_INSTALLED_COMPS'
       tables
         tt_comptab       = it_sp
       exceptions
         no_release_found = 1
         wrong_release    = 2
         .
  if sy-subrc = 0.
    sort it_sp by component.
    max_sp1 = max_sp2 = max_sp3 = max_sp4 = 1.
    loop at it_sp assigning <fs4>.
      grow <fs4>-component  len_sp1 max_sp1.
      grow <fs4>-desc_text  len_sp2 max_sp2.
      grow <fs4>-extrelease len_sp3 max_sp3.
      grow <fs4>-release    len_sp4 max_sp4.
    endloop.

    ps_sp1 = 5.
    ps_sp2 = ps_sp1 + max_sp1 + spacing.
    ps_sp3 = ps_sp2 + max_sp2 + spacing.
    ps_sp4 = ps_sp3 + max_sp3 + spacing.
    u_sp   = ps_sp4 + max_sp4 - 5.
  else.
    free it_sp.
  endif.

*-Get SPAM version
  call function 'SPAM_VERSION'
       importing
         formatted = spam_vers
         .
endform. "GET_SP_INFO
*-----------------------------------------------------------------------
define uline_sp.
  new-line no-scrolling.
  write /5 sy-uline(u_sp).
end-of-definition. "ULINE_SP
*-----------------------------------------------------------------------
define toolbar.
  if f_toolbar = 'X'.
    tool_symb = sym_checkbox.

    write:
      tool_symb as symbol hotspot quickinfo 'Hide'(960)
    , rdev_icon as icon   hotspot quickinfo  text-064 "Jump to DEV
    , rqas_icon as icon   hotspot quickinfo  text-065 "Jump to QAS
    , rprd_icon as icon   hotspot quickinfo  text-066 "Jump to PRD
    , rusr_icon as icon   hotspot quickinfo  text-930 "Jump to ...
    .
    if p_mandt = sy-mandt.
      write
      dalv_icon as icon   hotspot quickinfo  text-116 "Display ALV
      .
    endif.
    if phone_flg = 'X'.
      write
      file_icon as icon   hotspot quickinfo  text-117 "Phones file
      .
    endif.
    write:
      mlog_icon as icon   hotspot quickinfo  text-118 "Message log
    , dlog_icon as icon   hotspot quickinfo  text-119 "Delete log
*   , space
    , peri_icon as icon   hotspot quickinfo  text-134 "Set period
    , lay2_icon as icon   hotspot quickinfo  text-135 "Scroll-boundary
*   , chck_icon as icon   hotspot quickinfo  q_chck   "F_CHKADDR 'Y/N'
*   , area_icon as icon   hotspot quickinfo  q_area   "Search area W/N
    , lang_icon as icon   hotspot quickinfo  text-114 "Language
    , selo_icon as icon   hotspot quickinfo  text-120 "Mark online
    , selr_icon as icon   hotspot quickinfo  text-121 "With refuser
    , ireg_icon as icon   hotspot quickinfo  text-154 "Not used logins
    , sela_icon as icon   hotspot quickinfo  text-122 "Mark ALL
    , seln_icon as icon   hotspot quickinfo  text-123 "Mark NONE
    , seli_icon as icon   hotspot quickinfo  text-124 "Invert marks
    , excl_icon as icon   hotspot quickinfo  text-321 "Exclude
    , crop_icon as icon   hotspot quickinfo  text-975 "Crop list
    , ctlc_icon as icon   hotspot quickinfo  text-898 "Copy to clipb.
    , ctlv_icon as icon   hotspot quickinfo  text-899 "Mark from clpb.
    , xcel_icon as icon   hotspot quickinfo  text-341 "Export to Excel
    , refr_icon as icon   hotspot quickinfo  text-115 "Refresh
    .
    if not expert is initial.
      write
      debu_icon as icon   hotspot quickinfo 'Debug ABAP'(223) "Debug
      .
    endif.
  else.
    tool_symb = sym_large_square.

    write:
      tool_symb as symbol hotspot quickinfo 'Show'(961)
    , 'Inplace toolbar'(897)
    .
  endif.
end-of-definition. "TOOLBAR
*-----------------------------------------------------------------------
form write_sp_info.
  constants:
    cl_comp   type i value col_key
  , cl_extr   type i value col_positive
  .
  data:
    title_sp(132)
  , title_len type i
  , st_vers   like title_sp
  , max_spv   type i
  , ps_sp5    type i
  .
  if it_sp[] is initial. exit. endif.

  title_sp = 'Levels of installed components (Support Packages)'(973).
  if title_len < u_sp. title_len = u_sp. endif.
  max_spv = ps_sp4 - ps_sp2 + max_sp4.
  ps_sp5  = ps_sp1 + u_sp - 2.

  concatenate 'Support Package Manager version'(420)
               spam_vers
         into  st_vers
               separated by space
               .
  condense st_vers.

  skip.
  new-line no-scrolling.
  if f_spinfo = 'X'.
    pack_symb = sym_right_triangle.
    format color col_heading inverse.
    write:
     /3 pack_symb as symbol hotspot quickinfo 'Hide'(960)
    , at ps_sp1(title_len) title_sp color col_normal inverse off
    ,(2) space
    .
    toolbar.
    uline_sp.

*---Write SPAM version
    new-line no-scrolling.
    write:
      at ps_sp1(max_sp1) spam_symb
        as symbol hotspot quickinfo 'Call SPAM'(421)
        color col_heading inverse off
      .
    format color col_heading inverse off.
    write:
      at ps_sp2(max_spv) st_vers
    , at ps_sp5 spre_symb
        as symbol hotspot quickinfo 'Refresh'(422)
        color col_heading inverse off
    .
*---Write version of installed components
    format color col_heading inverse.
    loop at it_sp assigning <fs4>.
      new-line no-scrolling.
      write:
        at ps_sp1(max_sp1) <fs4>-component  color = cl_comp inverse off
      , at ps_sp2(max_sp2) <fs4>-desc_text
      , at ps_sp3(max_sp3) <fs4>-extrelease color = cl_extr inverse off
      , at ps_sp4(max_sp4) <fs4>-release
      .
    endloop.
    uline_sp.
  else.
    pack_symb = sym_down_triangle.
    format color col_heading inverse.
    write:
     /3  pack_symb as symbol hotspot quickinfo 'Show'(961)
    , at ps_sp1 'Support Packages Info'(974)
    ,(2) space
    .
    toolbar.
  endif.
endform. "WRITE_SP_INFO
*-----------------------------------------------------------------------
form sort_and_print using f1 f2 f3 changing ascend type c.
  move: f1 to sav1, f2 to sav2, f3 to sav3, ascend to sav4.
  if ascend = 'X'.                        "Sorting IT by F1, F2, F3..
    sort it  ascending by (f1) (f2) (f3).              "   ..ASCENDING
  else.                                   "Sorting IT by F1, F2, F3..
    sort it descending by (f1) (f2) (f3).              "  ..DESCENDING
  endif.
  perform toggle_flag changing ascend.    "Toggle sorting rule
  perform print_table.                    "Print results on the screen
endform. "SORT_AND_PRINT
*-----------------------------------------------------------------------
form print_list_as_is.
  if sav4 = 'X'. sort it  ascending by (sav1) (sav2) (sav3).
           else. sort it descending by (sav1) (sav2) (sav3). endif.
  perform print_table.
endform. "PRINT_LIST_AS_IS
*-----------------------------------------------------------------------
form print_list_by_bname.
  s_and_p 'BNAME' 'NAME_LAST' 'NAME_FIRST' srt_bnam.
endform. "PRINT_LIST_BY_BNAME
*-----------------------------------------------------------------------
form print_list_by_name_last.
  s_and_p 'NAME_LAST' 'NAME_FIRST' 'BNAME' srt_naml.
endform. "PRINT_LIST_BY_NAME_LAST
*-----------------------------------------------------------------------
form print_list_by_name_first.
  s_and_p 'NAME_FIRST' 'NAME_LAST' 'BNAME' srt_namf.
endform. "PRINT_LIST_BY_NAME_FIRST
*-----------------------------------------------------------------------
form print_list_by_tel_number.
  if p_expand is initial.
    s_and_p 'TEL_NUMDIS' 'BNAME' 'NAME_LAST' srt_teln.
  else.
    s_and_p 'TEL_NUMBER' 'BNAME' 'NAME_LAST' srt_teln.
  endif.
endform. "PRINT_LIST_BY_TEL_NUMBER
*-----------------------------------------------------------------------
form print_list_by_tel_extens.
  s_and_p 'TEL_EXTENS' 'BNAME' 'NAME_LAST' srt_tele.
endform. "PRINT_LIST_BY_TEL_EXTENS
*-----------------------------------------------------------------------
form print_list_by_function.
  s_and_p 'FUNCTION'   'BNAME' 'NAME_LAST' srt_func.
endform. "PRINT_LIST_BY_FUNCTION
*-----------------------------------------------------------------------
form print_list_by_department.
  s_and_p 'DEPARTMENT' 'BNAME' 'NAME_LAST' srt_depa.
endform. "PRINT_LIST_BY_DEPARTMENT
*-----------------------------------------------------------------------
form print_list_by_building.
  s_and_p 'BUILDING' 'ROOMNUMBER'  'BNAME' srt_buil.
endform. "PRINT_LIST_BY_BUILDING
*-----------------------------------------------------------------------
form print_list_by_roomnumber.
  s_and_p 'ROOMNUMBER' 'BUILDING'  'BNAME' srt_room.
endform. "PRINT_LIST_BY_ROOMNUMBER
*-----------------------------------------------------------------------
form print_list_by_trdat.
  s_and_p 'TRDAT'      'LTIME'     'BNAME' srt_trda.
endform. "PRINT_LIST_BY_TRDAT
*-----------------------------------------------------------------------
form print_list_by_modbe.
  s_and_p 'MODBE'      'MODDA'     'MODTI' srt_modb.
endform. "PRINT_LIST_BY_MODBE
*-----------------------------------------------------------------------
form print_list_by_modda.
  s_and_p 'MODDA'      'MODTI'     'MODBE' srt_modd.
endform. "PRINT_LIST_BY_MODDA
*-----------------------------------------------------------------------
form print_list_by_aname.
  s_and_p 'ANAME'      'ERDAT'     'BNAME' srt_anam.
endform. "PRINT_LIST_BY_ANAME
*-----------------------------------------------------------------------
form print_list_by_erdat.
  s_and_p 'ERDAT'      'BNAME' 'NAME_LAST' srt_erda.
endform. "PRINT_LIST_BY_ERDAT
*-----------------------------------------------------------------------
form navigate_to_object using value(object)   like e071-object
                              value(obj_name) like e071-obj_name
                              .
*-Check for active ARFC calls
  check_arfc.

  call function 'TR_OBJECT_JUMP_TO_TOOL'
       exporting
         iv_pgmid          = 'R3TR'
         iv_object         =  object
         iv_obj_name       =  obj_name
         iv_action         = 'SHOW'
       exceptions
         jump_not_possible =  1
         .
  if sy-subrc <> 0.
*   if sy-msgid = 'EU' and sy-msgno = 297.
*     app_log 'OZ' '037' obj_name space space space.
**---'Transaction & is an area menu and cannot be executed'
*     message e037(oz) with obj_name.
**    perform navigate_to_menu using obj_name.
*   else.
      app_log sy-msgid sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      message id sy-msgid type 'E' number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*   endif.
  endif.
endform. "NAVIGATE_TO_OBJECT
*-----------------------------------------------------------------------
define navigate.
  perform navigate_to_object using &1 &2.
end-of-definition. "NAVIGATE
*-----------------------------------------------------------------------
*include zbdcincl.
*
*form navigate_to_menu using value(v_menu).
*  dyn 'SAPLBMEN'     '0200'.
*  fld 'BDC_CURSOR'   'BMENUNAME-ID'.
*  fld 'BDC_OKCODE'   '=SHOW'.
*  fld 'BMENUNAME-ID'  v_menu.
*
** dyn 'SAPMSSY0'     '0120'.
** fld 'BDC_OKCODE'   '=TRRT'.
*
*  tra 'SE43'.
*endform. "NAVIGATE_TO_MENU
*-----------------------------------------------------------------------
form telnet_or_ping.
  data:
    v_program(128)
  , v_cmdln(1024)
  .
  concatenate sy-host '( IP address ='(130) host_ip ')' "#EC NOTEXT
         into pop_txt
              separated by space
              .
  clear ans.
  call function 'POPUP_TO_DECIDE'
       exporting
         defaultoption     =  2
         textline1         = 'Please choose a command for'(125)
         textline2         =  pop_txt
         textline3         = 'TELNET or PING'(127)
         text_option1      = 'telnet'(128)
         text_option2      = 'ping'(129)
         icon_text_option1 = 'ICON_BIW_MONITOR'
         icon_text_option2 = 'ICON_RELATIONSHIP' "ICON_EXECUTE_OBJECT
         titel             = 'Execute command'(126)
         start_column      =  25
         start_row         =  6
         cancel_display    = 'X'
       importing
         answer            =  ans
         .
  case ans.
    when '1'.    v_program = 'telnet'.
                              v_cmdln = host_ip.
    when '2'.    v_program = 'ping'.
                 concatenate '-t' host_ip
                        into  v_cmdln
                              separated by space
                              .
*   when 'A'.
    when others. perform action_cancelled.
                 exit.
  endcase.

  call function 'WS_EXECUTE'
       exporting
         commandline        =  v_cmdln
*        inform             = 'X'  "// synchronous
         program            =  v_program
       exceptions
*        frontend_error     =  1
*        no_batch           =  2
*        prog_not_found     =  3
*        illegal_option     =  4
*        gui_refuse_execute =  5
*        others             =  6
         others             =  0
         .
*      if sy-subrc <> 0.
*        message e...().
*      endif.

endform. "TELNET_OR_PING
*-----------------------------------------------------------------------
form set_pointer.
  point_bname = sel_bname.
  if point_bname = sy-uname. pnt = col_positive.
                       else. pnt = col_heading.  endif.
endform. "SET_POINTER
*-----------------------------------------------------------------------
form at_line_selection.
  if p_scroll = 'X' and sy-cucol < rm1.
    perform line_selection using sy-cucol.
  else.
    abscol = sy-cucol + sy-staco - 1.
    perform line_selection using abscol.
  endif.
endform. "AT_LINE_SELECTION
*-----------------------------------------------------------------------
form line_selection using col like sy-staco.
  constants
    c_shift   like sy-cucol value 19
  .
  data
    tmp_shift like sy-cucol
  .
  clear nav. get cursor field nav.

  case sy-curow.                          "Case of line in the window
    when head_ce.                         " (clicked on header line)
      if nav = 'F_SELE'.
        perform toggle_flag changing f_sele.
        if f_sele = 'X'. perform cmd_select_all.
                   else. perform cmd_select_none. endif.
      elseif nav = 'EXPA_SYMB'.
*-------Expand/Collapse TEL_NUMBER field
        perform cmd_expand_squeeze.
      elseif nav = 'QCPY_SYMB'.
*-------Quick copy username when surname is clicked - ON/OFF
        perform cmd_cpynam.
      elseif nav = 'SY-VLINE'.
*-------Scroll list to current column
        if p_scroll = 'X'.
          if sy-cucol > c_shift.
            tmp_shift = sy-cucol - c_shift.
            scroll list right by tmp_shift places.
*           tmp_shift = sy-staco + sy-cucol - c_shift.
*           scroll list to column tmp_shift.
          elseif sy-cucol = 2.
            scroll list to column 1.        "set user-command 'PS--'.
          endif.
        else.
          if sy-cucol = 2.
            scroll list to column 1.        "set user-command 'PS--'.
          else.
            tmp_shift = sy-staco + sy-cucol - 2.
            if tmp_shift > 0.
              scroll list to column tmp_shift.
            endif.
          endif.
        endif.
*-----Sort by clicked column
      elseif col between l01 and r01.       "L01 <= Column <= R01
        perform print_list_by_bname.        "sort by 'BNAME'
      elseif col between l02 and r02.
        perform print_list_by_name_last.    "sort by 'NAME_LAST'
      elseif col between l03 and r03.
        perform print_list_by_name_first.   "sort by 'NAME_FIRST'
      elseif col between l04 and r04.
        perform print_list_by_tel_number.   "sort by 'TEL_NUMBER'
      elseif col between l05 and r05.
        perform print_list_by_tel_extens.   "sort by 'TEL_EXTENS'
      elseif col between l06 and r06.
        perform print_list_by_function.     "sort by 'FUNCTION'
      elseif col between l07 and r07.
        perform print_list_by_department.   "sort by 'DEPARTMENT'
      elseif col between l08 and r08.
        perform print_list_by_building.     "sort by 'BUILDING'
      elseif col between l09 and r09.
        perform print_list_by_roomnumber.   "sort by 'ROOMNUMBER'
      elseif col between l10 and r10.
        perform print_list_by_trdat.        "sort by 'TRDAT'+'LTIME'
      elseif col between l12 and r12.
        perform print_list_by_modbe.        "sort by 'MODBE'
      elseif col between l13 and r13.
        perform print_list_by_modda.        "sort by 'MODDA'
      elseif col between l14 and r14.
        perform print_list_by_aname.        "sort by 'ANAME'
      elseif col between l15 and r15.
        perform print_list_by_erdat.        "sort by 'ERDAT'
      endif.

    when others.
      case nav.
*-------Send POPUP message to user
        when 'IT-ICONID'.
          perform send_popup_single.
*         perform set_pointer.

*-------Call transaction SU01
        when 'IT-BNAME'.
          perform call_su01.
*         perform set_pointer.

*-------Mark/unmark user
        when 'IT-MARK'.
          perform toggle_user.
*         perform set_pointer.

*-------Process with reference to another user
        when 'LINK_SYMB'.
          perform at_link_click.
*         perform set_pointer.

*-------Show/hide HTML pane
        when 'IT-TEL_NUMBER'
          or 'IT-TEL_NUMDIS'
          or 'IT-TEL_EXTENS'
              .
          perform toggle_html_pane_main.

*-------Show what user doing now
        when 'IT-NAME_LAST'
          or 'IT-NAME_FIRST'
*         or 'IT-TEL_NUMBER'
*         or 'IT-TEL_NUMDIS'
*         or 'IT-TEL_EXTENS'
          or 'IT-FUNCTION'
          or 'IT-DEPARTMENT'
          or 'IT-BUILDING'
          or 'IT-ROOMNUMBER'
          or 'IT-TRDAT'
          or 'IT-LTIME'
          or 'IT-MODDA'
          or 'IT-MODTI'
          or 'IT-MODBE'
          or 'IT-ANAME'
          or 'IT-ERDAT'
              .
          if p_cpynam = 'X' and nav = 'IT-NAME_LAST'.
            cls usrlist.
            usrlist-bname = it-bname. append usrlist.
            perform export_to_clipboard_ownmsg
              tables usrlist
              using 'X'
                     it-bname
              .
          else.
            perform show_user_activity.
*           perform set_pointer.
          endif.

*-------Show what user doing now
        when 'SY-VLINE'.
          if col between l02 and r15.       "L02 <= Column <= R15
            perform show_user_activity.
*           perform set_pointer.
          endif.

*-------Client Administration
        when 'P_MANDT'.
          if expert is initial.
            perform call_transaction using 'SCC4'. "V_T100  SHOW
          else.
            perform call_transaction using 'OY25'. "V_T100  UPDATE
          endif.

*-------Maintaining Logical Systems
        when 'LOGSYS'.
          perform call_transaction using 'BD54'. "V_TBDLS UPDATE
*         set_fcode '/*SM30 VIEWNAME=V_TBDLS;SHOW=X;'. "not satisfy

*-------Show SAP licenses
        when 'SY-SYSID'.
          perform sl_read_data.
          perform show_licenses.

*-------Show SAP Release Information
        when 'SY-SAPRL'
          or 'KERNINFO'
*         or 'KERN_REL6'
*         or 'KERN_PATCH6'
*         or 'SY-HOST'
              .
          call function 'TH_POPUP_RELEASE_INFO'
               exporting
                 server = myname
               exceptions
                 others = 0
                 .
*-------Telnet to or ping this Application Server
        when 'SY-HOST'.
          perform telnet_or_ping.

*-------Call 'System -> Status'
        when 'PLATFORM'.
          set_fcode '?STAT'.

*-------Call Selection-Screen
        when 'SUM_USR'.
          perform call_selection_screen.

*-------Mark locked users
        when 'SUM_LCK'.
          perform cmd_select_red.

*-------Mark users with incorrect logon attempts
        when 'SUM_ERR'.
          perform cmd_select_yellow.

*-------Show/Hide info about installed Support Packages/Add-Ons
        when 'PACK_SYMB'.
          perform toggle_flag changing f_spinfo.
          perform print_table.
          perform jump_to_last_page.

*-------Refresh Info about Installed Support Packages/Add-Ons
        when 'SPRE_SYMB'.
          perform get_sp_info.
          perform print_table.

*-------Call transaction SPAM
        when 'SPAM_SYMB'.
          perform call_user_transaction using 'SPAM' space.

*-------Show/Hide Extended Inplace Toolbar
        when 'TOOL_SYMB'.
          perform toggle_flag changing f_toolbar.
          perform print_table.

*-------Go to DEV server
        when 'RDEV_ICON'.
          perform remote_transaction using r_tcode dest_dev.

*-------Go to QAS server
        when 'RQAS_ICON'.
          perform remote_transaction using r_tcode dest_qas.

*-------Go to PRD server
        when 'RPRD_ICON'.
          perform remote_transaction using r_tcode dest_prd.

*-------Go to user-defined server
        when 'RUSR_ICON'.
          perform goto_given_remote_server.

*-------Get logon limit (in days)
        when 'PERI_ICON'.
          perform set_period.

*-------Toggle F_CHKADDR ON/OFF
        when 'CHCK_ICON'.
          perform toggle_chkaddr.
          perform print_table.

*-------Set scroll-boundary ON/OFF
        when 'LAY2_ICON'.
          perform toggle_flag changing p_scroll.
          perform print_table.

*-------Switch language (partially)
        when 'LANG_ICON'.
          perform cmd_next_language_m.

*-------Select online users
        when 'SELO_ICON'.
          perform cmd_select_online.

*-------Select users with reference user
        when 'SELR_ICON'.
          perform cmd_select_with_refuser.

*-------Select users with unused logins
        when 'IUSR_ICON'
          or 'IREG_ICON'
              .
          perform cmd_select_not_used.

*-------Select users with unused logins
        when 'NOAD_ICON'
              .
          perform cmd_select_noaddr.

*-------Select all
        when 'SELA_ICON'.
          perform cmd_select_all.

*-------Deselect all
        when 'SELN_ICON'.
          perform cmd_select_none.

*-------Invert selection
        when 'SELI_ICON'.
          perform cmd_invert.

*-------Copy marked logins to clipboard
        when 'CTLC_ICON'.
          perform export_to_clipboard_main.

*-------Select users from clipboard
        when 'CTLV_ICON'.
          perform mark_from_clipboard.

*-------Crop view
        when 'CROP_ICON'.
          perform crop_list.

*-------Clear command line
        when 'CLEA_ICON'.
          perform clear_cmdl.

*-------Paste text from clipboard into command line
        when 'PAST_ICON'.
          perform paste_cmdl.

*-------Choose mode: SEARCH, MARK, FILTER, COMMAND
        when 'CHOO_ICON'.
          read line 1 field value cmd into new_cmd.
*         if new_cmd is initial.
            perform switch_cmd_mode.
*         else.
*           set_fcode 'OKAY'.
*         endif.

*-------Search text entered in command line
        when 'MODE_ICON'.
          read line 1 field value cmd into new_cmd.
**        if new_cmd is initial.
**          perform switch_cmd_mode.
**        else.
*           set_fcode 'OKAY'.
            perform process_input_m using 'X'.
**        endif.

*-------Toggle search area range: WIDE/NARROW
        when 'AREA_ICON'.
          perform toggle_range.

*-------Refresh list
        when 'REFR_ICON'.
          perform refresh_list.
          perform jump_to_last_page.
*---------Count users without address (if check is active)
*         perform count_and_report_noaddr.


*-------Display message log
        when 'MLOG_ICON'.
          perform show_log.

*-------Clear message log
        when 'DLOG_ICON'.
          perform clear_log.

*-------Display ALV-standard
        when 'DALV_ICON'.
          perform display_alv.

*-------Display content of phones' file
        when 'FILE_ICON'.
          perform show_phones_file_content.

*-------Switch to DEBUG
        when 'DEBU_ICON'.
          perform cmd_debug.

*-------Exclude from view
        when 'EXCL_ICON'.
          if sy-lilli > last_ln.
            perform exclude_from_list.
            perform jump_to_last_page.
          else.
            perform exclude_from_list.
          endif.

*-------Export data to Excel
        when 'XCEL_ICON'.
          perform export_to_excel_main.

*-------Display program source
        when 'SY-REPID'.
          move sy-repid to v_obj_name.
          concatenate v_obj_name q_info_prog
                 into pop_txt
                      separated by space
                      .
          confirm_step
            'Y'
            'Want to display source code of the program'(885)
             pop_txt
            'Navigation confirmation'(886)
             .
          if ans = 'J'.
            navigate 'PROG' v_obj_name.
          else. perform action_cancelled. endif.

*-------Display definition of current transaction code
        when 'SY-TCODE'.
          move sy-tcode to v_obj_name.
          navigate 'TRAN' v_obj_name.

*-------Switch Refresh-on-Return ON/OFF
        when 'AUTO_SYMB'.
          perform toggle_flag changing p_refr.
          perform print_table.
          perform report_p_refr_status.

*-------Switch Autorefresh ON/OFF
*       when 'AREF_SYMB'.
        when 'AREF_ICON'.
          perform toggle_aref.
          perform print_table.

*-------Switch F_KEEP ON/OFF
        when 'KEEP_ICON'.
          perform toggle_keep.

*-------Switch Command line ON/OFF
        when 'CMDL_SYMB'
*         or 'CMDL_ICON'
              .
          perform toggle_cmdl.

*-------Switch F_SURNAM ON/OFF
        when 'IMPM_ICON'
*         or 'IMPM_SYMB'
              .
          perform toggle_impm.

*-------Display HELP on commands
        when 'CMD'
              .
          perform display_commands.

*-------Switch F_SHOWMODE ON/OFF
*       when 'CMD'
*             .
*         perform toggle_showimpm.

*-------Navigation is not possible
        when others.
*         navigation_impossible.

      endcase.
  endcase.
endform. "LINE_SELECTION
*-----------------------------------------------------------------------
*form add_users_without_address.
*  clear sum_miss.
*  describe table it lines sy-tfill.
*  select count( * ) up to p_rows rows
*                    from usr02 client specified
*                    where mandt = p_mandt
*                      and bname in so_bname
*                      and ustyp in so_ustyp
*                          .
*  sum_miss = sy-dbcnt - sy-tfill.
*  if sum_miss > 0.
**   app_log_z2_2 '031' sum_miss text-276.
**   message s031 with sum_miss 'users without address data'(276).
*    select * up to p_rows rows
*             from usr02 client specified
*             where mandt = p_mandt
*               and bname in so_bname
*               and ustyp in so_ustyp
*                   .
*      read table it with key bname = usr02-bname.
*      if sy-subrc <> 0.
*        clear it.
*        it-mandt      =  usr02-mandt.
*        it-bname      =  usr02-bname.
*        it-locnt      =  usr02-locnt.
*        it-uflag      =  usr02-uflag.
*        it-aname      =  usr02-aname.
*        it-erdat      =  usr02-erdat.
*        it-trdat      =  usr02-trdat.
*        it-ltime      =  usr02-ltime.
**       it-persnumber = .
**       it-addrnumber = .
**       it-modda      = .
**       it-modti      = .
**       it-modbe      = '?????????????'.
**       it-title      = .
**       it-name_first = '?????????????'.
**       it-name_last  = '?????????????'.
***      it-sex        = .
**       it-department = '?????????????'.
**       it-function   = '?????????????'.
**       it-building   = '?????????????'.
***      it-floor      = .
**       it-roomnumber = '?????'.
**       it-tel_number = '?????????????'.
**       it-tel_numdis = '?????????????'.
**       it-tel_extens = '?????????????'.
***      it-refuser    = .
***      it-mark       = .
*        it-noaddr     = 'X'.
***      it-online     = .
**       it-iconid     = '@CZ@'. " icon_wf_workitem_cancel
***      it-iconname   = .
**       it-c_bna      = col_normal.
**       it-c_ana      = cl_noaddr.
**       it-c_erd      = cl_noaddr.
**       it-c_trd      = cl_noaddr.
**       it-c_lti      = cl_noaddr.
**       it-c_mda      = cl_noaddr.
**       it-c_mti      = cl_noaddr.
**       it-c_mbe      = cl_noaddr.
**       it-c_nfi      = cl_noaddr.
**       it-c_nla      = cl_noaddr.
**       it-c_dep      = cl_noaddr.
**       it-c_fun      = cl_noaddr.
**       it-c_bui      = cl_noaddr.
**       it-c_roo      = cl_noaddr.
**       it-c_tnu      = cl_noaddr.
**       it-c_tex      = cl_noaddr.
*        append it.
*      endif.
*    endselect.
*  endif.
*endform. "ADD_USERS_WITHOUT_ADDRESS
*-----------------------------------------------------------------------
form add_users_without_address.
  field-symbols <fs_usr02> type usr02.
  data:
    it_usr02 type standard table of usr02
  , wa_usr21 like usr21
  .
*-Clean up IT_USR02
  cls it_usr02.
* clear sum_miss.

*-Get all user master records according to selection criteria
  select * up to p_rows rows
           from usr02 client specified
           into table it_usr02
           where mandt = p_mandt
             and bname in so_bname
             and ustyp in so_ustyp
                 .
*-Cycle
  loop at it_usr02 assigning <fs_usr02>.
*---Is address data exist and isn't it initial?
    select * from usr21 client specified
             up to 1 rows
             into wa_usr21
             where mandt = p_mandt
               and bname = <fs_usr02>-bname
                   .
      if ( sy-subrc eq 0 and wa_usr21-persnumber is initial ) or
           sy-subrc ne 0
           .
*-------Address does not exist or it has initial value

*-------Redundant check, may be omitted: is entry already present in IT?
        read table it with key bname = <fs_usr02>-bname.
        if sy-subrc <> 0.
*         add 1 to sum_miss.
          clear it.
          move-corresponding <fs_usr02> to it.
          it-noaddr = 'X'.
*---------Append this user to main table IT
          append it.
        endif.

      endif.
    endselect.
  endloop.

*-Free memory occupied by IT_USR02
  free it_usr02.
endform. "ADD_USERS_WITHOUT_ADDRESS
*-----------------------------------------------------------------------
form cmd_debug.
  set_fcode '/h'.
endform. "CMD_DEBUG
*-----------------------------------------------------------------------
form jump_to_first_page.
  set_fcode 'P--'.
endform. "JUMP_TO_FIRST_PAGE
*-----------------------------------------------------------------------
form jump_to_last_page.
  set_fcode 'P++'.
endform. "JUMP_TO_LAST_PAGE
*-----------------------------------------------------------------------
form cmd_refresh_list_force.
  perform call_rfc_ping_wait.
  perform refresh_list_force.
endform. "CMD_REFRESH_LIST_FORCE
*-----------------------------------------------------------------------
form cmd_refresh_list.
  perform call_rfc_ping_wait.
  perform refresh_list.
endform. "CMD_REFRESH_LIST
*-----------------------------------------------------------------------
form cmd_fresh_list.
  perform call_rfc_ping_wait.
  perform fresh_list.
endform. "CMD_FRESH_LIST
*-----------------------------------------------------------------------
form save_entries.
  cls usrlist.
  loop at it assigning <fs>.
    usrlist-bname = <fs>-bname. append usrlist.
  endloop.

*-Save indicator
  sav_crop = ind_crop.
endform. "SAVE_ENTRIES
*-----------------------------------------------------------------------
form restore_entries.
*-All new entries must be determined then deleted
  loop at it assigning <fs>.
    read table usrlist with key bname = <fs>-bname.
    if sy-subrc <> 0. <fs>-mark = 'X'. endif.
  endloop.
  delete it where mark = 'X'.

*-Restore indicator
  ind_crop = sav_crop.
endform. "RESTORE_ENTRIES
*-----------------------------------------------------------------------
form refresh_list_ex using keep_flag.
* set run time analyzer on.  "<== only for trace in SE30
  perform get_data using keep_flag.
  perform print_list_as_is.  "<== PRINT_TABLE contains GET_ACTIVITY
* set run time analyzer off. "<== only for trace in SE30
endform. "REFRESH_LIST_EX
*-----------------------------------------------------------------------
form fresh_list.
  perform refresh_list_ex using 'X'.
endform. "FRESH_LIST
*-----------------------------------------------------------------------
form refresh_list.
  perform refresh_list_ex using f_keep.
endform. "REFRESH_LIST
*-----------------------------------------------------------------------
form refresh_list_force.
  perform refresh_list_ex using ' '.
endform. "REFRESH_LIST_FORCE
*-----------------------------------------------------------------------
form set_variant_name.
  if sy-slset is initial.
    clear    slset.
  else.
    concatenate '/' sy-slset '/' into slset separated by space.
    condense slset.
  endif.
endform. "SET_VARIANT_NAME
*-----------------------------------------------------------------------
form get_data using keep_flag.  " * * * PRIMARY DATA SELECTION * * *
*-Save existing entries
  if keep_flag = 'X'. perform save_entries. endif.

  perform set_variant_name.
**include zqueryrun.      "<== This is too hard and no good idea!
  cls it.                 "Clean up content and header of internal table
  clear: f_sele, ind_crop."Clear Checkbox ALL/NONE, CROPPED indicator

  prev_sum = sum_usr.     "Remember previous number of users

  perform issue_select.

*-Primary select
  select l~mandt
         l~bname
         l~ustyp
         l~class
         l~locnt
         l~uflag
         l~aname
         l~erdat
         l~trdat
         l~ltime
         k~persnumber
         k~addrnumber
*        a~modda
*        a~modti
*        a~modbe
*        p~title
         p~name_first
         p~name_last
*        p~sex
         c~department
         c~function
         c~building
*        c~floor
         c~roomnumber
         c~tel_number
         c~tel_extens
         into corresponding fields of table it
         up to p_rows rows
         from  ( ( (            usr02      as l
                     inner join usr21      as k
                        on l~mandt      = k~mandt      and
                           l~bname      = k~bname      )
*                    inner join usgrp_user as g
*                       on l~mandt      = g~mandt      and
*                          l~bname      = g~bname      )
*--<<<----For pooled tables like a USR04 JOIN is not allowed!-----<<<--*
*                    inner join usr04      as a
*                       on l~mandt      = a~mandt      and
*                          l~bname      = a~bname      )
*--<<<----For pooled tables like a USR04 JOIN is not allowed!-----<<<--*
                     inner join adrp       as p
                        on l~mandt      = p~client     and
                           k~persnumber = p~persnumber )
                     inner join adcp       as c
                        on l~mandt      = c~client     and
                           k~addrnumber = c~addrnumber and
                           k~persnumber = c~persnumber )
         client specified
         where l~mandt     =  p_mandt
*--> OLD!  and not l~bname in ('SAP*', 'DDIC', 'TMSADM', 'EARLYWATCH')
           and l~bname     in so_bname
           and l~ustyp     in so_ustyp

*    A - Dialog
*    B - System user (internal RFC and background processing)
*    C - Communication user (external RFC) (no dialog logon)
*    L - Reference user
*    S - Service user (permanent password, parallel logon allowed)

           and l~class     in so_class
*          and g~usergroup in so_class
           and p~date_from =  c_date1
*          and p~date_to   =  c_date2
           and p~nation    =  langver
           and c~date_from =  c_date1
*          and c~date_to   =  c_date2
           and c~nation    =  langver
               .
  if f_chkaddr = 'X'. " and p_rows is initial.
*---Check users with missing address data
    perform add_users_without_address.
  endif.

*-Keep previous entries only
  if keep_flag = 'X'.
    perform restore_entries.
  endif.

  if so_group[] is initial.
    clear f_group.
  else.
    move 'X' to f_group.
    sort it by bname.
    cls it_usrtab.
    select distinct bname into table it_usrtab
                          from usgrp_user client specified
                          where mandt     =  p_mandt
                            and usergroup in so_group
                                .
  endif.

  loop at it assigning <fs>.
    select single modda
                  modti
                  modbe
                  into corresponding fields of <fs>
                  from usr04 client specified
                  where mandt = <fs>-mandt
                    and bname = <fs>-bname
                        .
    if sy-subrc = 0.
      if not phone_flg is initial.
        read table it_phone with key bname = <fs>-bname binary search.
        if sy-subrc = 0. move-corresponding it_phone to <fs>. endif.
      endif.
*     modify it.
    endif.

*---Prepare phone numbers for display: (999)111-22-33 -> 111-22-33
    <fs>-tel_numdis = <fs>-tel_number.
*   if p_expand is initial.
      shift <fs>-tel_numdis up to ')'.
      if sy-subrc = 0. shift <fs>-tel_numdis. endif.
*   endif.

*   if sy-saprl ge c_saprl.
      select single refuser
             from usrefus client specified
             into <fs>-refuser
             where mandt = <fs>-mandt
               and bname = <fs>-bname
                   .
*     if sy-subrc = 0 and it-refuser <> space. modify it. endif.
*   endif.
    if f_group = 'X'.
      read table it_usrtab with key table_line = <fs>-bname
                 binary search
                 transporting no fields
                 .
      if sy-subrc <> 0. move 'X' to <fs>-mark. endif.
    endif.
  endloop.

  if f_group = 'X'. delete it where mark = 'X'. endif.
* describe table it lines sum_usr.

*-Count users without address (if check is active)
  perform count_and_report_noaddr.

  perform get_logical_system using p_mandt
                          changing logsys
                                   .
endform. "GET_DATA
*-----------------------------------------------------------------------
form get_logical_system using l_mandt  like t000-mandt
                     changing l_logsys like t000-logsys
                              .
  if l_mandt = sy-mandt.
    call function 'OWN_LOGICAL_SYSTEM_GET'
         importing
           own_logical_system             = l_logsys
         exceptions
           own_logical_system_not_defined = 1
           others                         = 2
           .
  else.
    select single logsys into (l_logsys)
                         from t000 client specified
                         where mandt = l_mandt
                               .
  endif.
  if sy-subrc <> 0. clear l_logsys. endif.
endform. "GET_LOGICAL_SYSTEM
*-----------------------------------------------------------------------
form get_activity.
  refresh it41.
  select bname server
         into corresponding fields of table it41
         from usr41 client specified
              where mandt = p_mandt
                    .
*-Sort itab with specified sort keys instead of default sort key
  sort it41 by bname server.
  delete adjacent duplicates from it41.

  clear sum_act.
  loop at it assigning <fs>.
    read table it41 with key bname = <fs>-bname
               binary search
               transporting no fields
               .
    if sy-subrc = 0.
      move 'X' to <fs>-online. add 1 to sum_act.
      read table it41 with key bname  = <fs>-bname
                               server = myname
                 binary search
                 transporting no fields
                 .
      if sy-subrc = 0.                               "My App.Server
        move v_icon1 to <fs>-iconid.
      else.                                          "Other App.Server
        move v_icon2 to <fs>-iconid.
      endif.
    else.
      clear <fs>-iconid.
*     clear <fs>-iconname.
      clear <fs>-online.
    endif.
*   modify it.
  endloop.
endform. "GET_ACTIVITY
*-----------------------------------------------------------------------
form count_and_report_noaddr.
  if f_chkaddr = 'X'.
    clear sum_miss.
    loop at it assigning <fs> where noaddr = 'X'.
      add 1 to sum_miss.
    endloop.
    if sum_miss > 0.
      app_log_z2_2 '031' sum_miss text-276.
      message s031 with sum_miss 'users without address data'(276).
    endif.
  endif.
endform. "COUNT_AND_REPORT_NOADDR
*-----------------------------------------------------------------------
form action_cancelled.
  app_log 'ES' '024' space space space space.
*-'Action cancelled by user'
  message s024(es).
endform. "ACTION_CANCELLED
*-----------------------------------------------------------------------
form clear_log.
  confirm_step 'N'
               'Do you want to clear'(091)
               'all log entries?'(092)
               'Clear log entries'(093)
                .
  case ans.
    when 'J'.    cls msg_log.
*                app_log_z2_0 '085'. "<-- Do not log this action :)
*---------------'All log entries erased'
                 message s085.
    when others. perform action_cancelled.
  endcase.
endform. "CLEAR_LOG
*-----------------------------------------------------------------------
form show_log.
  cls x_msg_log.
  if msg_log[] is initial.
*--'Log is empty'
    message s076.
  else.
    x_msg_log[] = msg_log[].
    call function 'SMPO_DISPLAY_MESSAGES'
         exporting
           titlebar      = 'Application Log'(828)
*          header_text_1 = ''
*          header_text_2 = ''
         tables
           messages      =  x_msg_log
           .
*   free x_msg_log.
  endif.
endform. "SHOW_LOG
*-----------------------------------------------------------------------
form simulate_sapgui_update.
  if p_refr = 'X'. perform simulate_sapgui_update_ex. endif.
endform. "SIMULATE_SAPGUI_UPDATE
*-----------------------------------------------------------------------
form simulate_sapgui_update_ex.
  set_fcode_ex 'REFR' 1.
  if sy-subrc <> 0.
    case sy-pfkey.
      when 'MAIN'. perform refresh_list.
      when 'USER'. perform smart_show_long_usr_info.
      when 'SESS'. perform refresh_list_s.
    endcase.
  endif.
endform. "SIMULATE_SAPGUI_UPDATE_EX
*-----------------------------------------------------------------------
form call_user_transaction using v_tcode like sy-tcode
                                 v_ttext like tstct-ttext
                                 .
*-Check for active ARFC calls
  check_arfc.

  if v_ttext is initial.
*---Try to get description from database
    perform get_tcode_text using langu v_tcode changing v_ttext.
  endif.

  move v_tcode to pop_txt. condense pop_txt.
  concatenate pop_txt v_ttext into pop_txt separated by ' - '.
  confirm_step 'Y'
               'Do you want to launch transaction'(911)
                pop_txt
               'Launch transaction'(910)
                .
  case ans.
    when 'J'.    perform call_transaction using v_tcode.
    when others.
*                perform simulate_sapgui_update.
*                perform action_cancelled.
  endcase.
endform. "CALL_USER_TRANSACTION
*-----------------------------------------------------------------------
form call_transaction using value(v_tcode). "like sy-tcode.
  tables
    tstc
  .
  data:
    mode    like sy-tabix                 "#EC NEEDED
  , t_tcode like sy-tcode

*---See include LSEUKTOP for more info on transaction types
  , hex_men type x value '01'
  .
*-Check for active ARFC calls
  check_arfc.

* commit work.
  select single * from tstc where tcode = v_tcode.

  if sy-subrc <> 0.
*   app_log_00_1 '031' v_tcode.
*--'Transaction & is unknown'
*   message e031(00) with v_tcode.
    app_log 'S#' '343' v_tcode space space space.
*--'Transaction & does not exist'
    message e343(s#) with v_tcode.
*   exit.
  elseif tstc-cinfo o hex_men.
*-Equivalent check:
* elseif tstc-pgmna(4) = 'MENU'.
*   app_log 'EU' '297' v_tcode space space space.
*--'&1 is an area menu. You can no longer edit area menus here.'
*   message e297(eu) with v_tcode.
    app_log 'OZ' '037' v_tcode space space space.
*--'Transaction & is an area menu and cannot be executed'
    message e037(oz) with v_tcode.
*   exit.
  endif.

  authority-check object 'S_TCODE'
    id 'TCD' field v_tcode
    .
  if sy-subrc <> 0.
*--'You are not authorized to use transaction &'
*   message s661(bt) with tcode.
*   app_log 'SF' '261' v_tcode space space space.
*--'You have no authorization for Transaction &'
*   message s261(sf) with v_tcode.
    app_log_00_1 '172' v_tcode.
*--'You are not authorized to use Transaction &'
    message s172(00) with v_tcode.
  else.
    perform issue_run_message using v_tcode space.
*   progress_ind 'Calling transaction'(666).
    if p_newmod = 'X'.
*-----Some redundance for compatibility to avoid dumps :)
      t_tcode = v_tcode.
      call function 'TH_CREATE_MODE'
           exporting
             transaktion    = t_tcode
           importing
             mode           = mode
           exceptions
             max_sessions   = 1
             internal_error = 2
             no_authority   = 3
             others         = 4
             .
      if sy-subrc <> 0.
        app_log 'SEU_MANAGER' '064' space space space space.
*------'Unable to create a new window'
        message s064(seu_manager).
      else.
        app_log 'SEU_MANAGER' '063' space space space space.
*------'Starting tool...'
        message s063(seu_manager).
      endif.
    else.
      call transaction v_tcode.
      perform simulate_sapgui_update.
    endif.
  endif.
endform. "CALL_TRANSACTION
*-----------------------------------------------------------------------
form call_sm02.                                  "System Messages
  perform call_transaction using 'SM02'.
endform. "CALL_SM02
*-----------------------------------------------------------------------
form call_sm04.                                  "Overview of Users
  case sy-pfkey.
    when 'USER'.  if p_usfilt = 'X'.
*-------------------Modes of specific user
                    perform call_sm04_user using sel_bname.
                  else.
*-------------------Modes of all users
                    perform call_transaction using 'SM04'.
                  endif.
    when  others. perform call_transaction using 'SM04'.
  endcase.
endform. "CALL_SM04
*-----------------------------------------------------------------------
form call_sm50.                                  "Process Overview
  case sy-pfkey.
    when 'USER'.  if p_usfilt = 'X'.
*-------------------Modes of specific user
                    perform call_sm50_user using sel_bname.
                  else.
*-------------------Modes of all users
                    perform call_transaction using 'SM50'.
                  endif.
    when  others. perform call_transaction using 'SM50'.
  endcase.
endform. "CALL_SM50
*-----------------------------------------------------------------------
form call_st22.                                  "ABAP dump analysis
  perform call_transaction using tr_st22.
endform. "CALL_ST22
*-----------------------------------------------------------------------
form call_sm12.                                  "Display & Delete Locks
  case sy-pfkey.
    when 'USER'.  if p_usfilt = 'X'.
*-------------------Cross-client, but user-specific locks
                    perform show_user_locks using space sel_bname.
                  else.
*-------------------Cross-client locks for all users
                    perform call_transaction using tr_sm12.
                  endif.
    when  others. perform call_transaction using tr_sm12.
  endcase.
endform. "CALL_SM12
*-----------------------------------------------------------------------
form call_sm13.                                  "Update Records
  perform call_transaction using tr_sm13.
endform. "CALL_SM13
*-----------------------------------------------------------------------
form call_os01.                                  "LAN Check by PING
**If a user has no authority to read system trace
* if auth_st0r is initial.
*   app_log_00_1 '149' obj_sysadm.
**-'You haven't authorization for object &'
*   message e149(00) with obj_sysadm.
**  exit.
* endif.

  perform call_transaction using 'OS01'.
endform. "CALL_OS01
*-----------------------------------------------------------------------
*orm call_pfcg.                                  "Profile Generator
* perform call_transaction using 'PFCG'.
*ndform. "CALL_PFCG
*-----------------------------------------------------------------------
*orm call_zpop.                                  "POPUP-messenger
* perform call_transaction using 'ZPOP'.
*ndform. "CALL_ZPOP
*-----------------------------------------------------------------------
*orm call_zlock.                                 "Mass (un)locking
* perform call_transaction using tr_zlock.
*ndform. "CALL_ZLOCK
*-----------------------------------------------------------------------
*data:
*  li_errtab type tt_errtab
*, l_errtab type bdcmsgcoll
*.
*data: begin of bdcdata occurs 1.  "Table for BDC call of tr. SU01
*        include structure bdcdata.
*data: end   of bdcdata.

*form add_to_log.
*  check not li_errtab[] is initial.
*  clear l_errtab.
*  loop at li_errtab into l_errtab.
*    clear msg_log.
*    msg_log-msgty = 'I'. "l_errtab-msgtyp.
*    msg_log-msgid =  l_errtab-msgid.
*    msg_log-msgno =  l_errtab-msgnr.
*    msg_log-msgv1 =  l_errtab-msgv1.
*    msg_log-msgv2 =  l_errtab-msgv2.
*    msg_log-msgv3 =  l_errtab-msgv3.
*    msg_log-msgv4 =  l_errtab-msgv4.
*    append msg_log.
*  endloop.
*endform. "ADD_TO_LOG
*-----------------------------------------------------------------------
*define bdc_su01.
** data l_errtxt like t100-text.
*  cls li_errtab.
*  set parameter id 'XUS' field sel_bname. "See help: SPA/GPA
** perform call_transaction using 'SU01'.
** call transaction 'SU01' using bdcdata.  "mode 'A' - by default
*  call transaction 'SU01' using bdcdata mode 'E'
*                                        messages into li_errtab.
*  perform add_to_log.
*
*  loop at li_errtab into l_errtab.
*    if  l_errtab-msgid = '01' and
*      (
**------'User was renamed. Old password is invalid'
*        l_errtab-msgnr = '091' or "<-- Does not matter here
**------'User & created'
*        l_errtab-msgnr = '102' or
**------'User & was saved'
*        l_errtab-msgnr = '226' or
**------'User & deleted'
*        l_errtab-msgnr = '232' or
**------'User & locked'
*        l_errtab-msgnr = '245' or
**------'User & unlocked, if this is permitted in this system'
*        l_errtab-msgnr = '246'
*      ).
**     set user-command 'REFR'. <- Does not work here
**     perform refresh_list.
*      perform simulate_sapgui_update.
*      exit.
*    endif.
*
**   message id l_errtab-msgid
**         type l_errtab-msgtyp
**       number l_errtab-msgnr
**         into l_errtxt with l_errtab-msgv1 l_errtab-msgv2.
**   ... more code ...
*  endloop.
*  free li_errtab.
*end-of-definition. "BDC_SU01
*-----------------------------------------------------------------------
form call_su01_ex using v_mandt like sy-mandt     "User Maintenance
                        v_bname like sy-uname
                       .
  constants:
    c_su01     like sy-tcode value 'SU01'
  , c_su01_nav like sy-tcode value 'SU01_NAV'
  .
*-Check for active ARFC calls
  check_arfc.

  if v_mandt <> sy-mandt.               "Check the client
    app_log_z2_1 '005' v_mandt. "y-mandt.
*--'You should to view/maintain this user's master record in client &1'
    message w005 with v_mandt. "y-mandt."Call SU01 here is not possible
*   exit.
  endif.

  if v_bname is initial.
    perform call_transaction using c_su01.
  else.
*   bdc_su01. " <-- BDC call is replaced with SU01_NAV call

    call function 'AUTHORITY_CHECK_TCODE'
         exporting
           tcode   = c_su01
         exceptions
           ok      = 1
           not_ok  = 2
           others  = 3
           .
    if sy-subrc ne 1.
      app_log_00_1 '172' c_su01.
*----'You are not authorized to use Transaction &'
      message s172(00) with c_su01.
    else.
      set parameter id 'XUS' field v_bname.
      perform call_transaction using c_su01_nav.
      perform simulate_sapgui_update.
    endif.
  endif.
endform. "CALL_SU01_EX
*-----------------------------------------------------------------------
form call_su01.                                  "User Maintenance
* get_and_check_sel_bname. " commit work.
  perform get_bname.
  perform call_su01_ex using p_mandt sel_bname.
endform. "CALL_SU01
*-----------------------------------------------------------------------
form toggle_flag changing flag type c.    "TOGGLES BOOLEAN VAR ON/OFF
  if flag is initial. move 'X' to flag. else. clear flag. endif.
endform. "TOGGLE_FLAG
*-----------------------------------------------------------------------
form top_of_page.
  case sy-pfkey.
    when 'MAIN'. perform do_header.
    when 'SESS'. perform do_header_s.
  endcase.
endform. "TOP_OF_PAGE
*-----------------------------------------------------------------------
form put_keep.
  if f_keep = 'X'.
    keep_icon = icon_hold.
    q_keep = 'Turn filtration keeping OFF'(314).
  else.
    keep_icon = icon_hold_undo.
    q_keep = 'Turn filtration keeping ON'(315).
  endif.

  write keep_icon as icon quickinfo q_keep hotspot.
endform. "PUT_KEEP
*-----------------------------------------------------------------------
form put_aref.
  format color col_background intensified off.

  if p_aref = 'X'.
*   aref_symb = sym_check_mark.
*   aref_icon = icon_system_start_recording.
*   aref_icon = icon_breakpoint.
    aref_icon = icon_system_cancel.
    q_aref = 'Turn autorefresh OFF'(798).
  else.
*   aref_symb = sym_bold_x.
*   aref_icon = icon_system_play.
*   aref_icon = icon_systems.
*   aref_icon = icon_location.
*   aref_icon = icon_oo_event.
*   aref_icon = icon_rating_neutral.
*   aref_icon = icon_complete.
*   aref_icon = icon_workflow_indefinite_step.
*   aref_icon = icon_time_ina.
    aref_icon = icon_system_okay.
    q_aref = 'Turn autorefresh ON'(799).
  endif.

* write aref_symb as symbol quickinfo q_aref inverse.
  if sy-pfkey <> 'MAIN'. write space no-gap. endif.
  write aref_icon as icon   quickinfo q_aref hotspot.
endform. "PUT_AREF
*-----------------------------------------------------------------------
form put_aref_updown.
  data:
    cl_secs type i
  , cl_ardn type i
  , cl_arup type i
  .
  check p_aref = 'X'
*   and sy-pfkey = 'USER'
  .
  format color col_background intensified off.

  q_ardn    = 'Decrease'(180).
  q_arup    = 'Increase'(181).
  cl_secs = cl_ardn = cl_arup = col_heading.

  case arfc_secs.
    when arfc_min.
      cl_ardn   = col_background.
      q_ardn    = 'Lower limit reached'(183).
    when arfc_max.
      cl_arup   = col_background.
      q_arup    = 'Upper limit reached'(184).
*   when others.
  endcase.

  write: space, ardn_symb as symbol
    color = cl_ardn inverse
    hotspot quickinfo q_ardn
*   no-gap
    .
  write (01) arfc_secs
    color = cl_secs inverse
            quickinfo 'Time interval'(182)
*   no-gap
    .
  write arup_symb as symbol
    color = cl_arup inverse
    hotspot quickinfo q_arup
*   no-gap
    .
endform. "PUT_AREF_UPDOWN
*-----------------------------------------------------------------------
form arfc_up.
  if arfc_secs < arfc_max. add 1 to arfc_secs. endif.
* set user-command 'REFR'.
endform. "ARFC_UP
*-----------------------------------------------------------------------
form arfc_down.
  if arfc_secs > arfc_min. subtract 1 from arfc_secs. endif.
* set user-command 'REFR'.
endform. "ARFC_DOWN
*-----------------------------------------------------------------------
form toggle_impm.
* if expert is initial. exit. endif.

  perform toggle_flag changing f_surnam.
  perform set_impm.
  perform print_table.
endform. "TOGGLE_IMPM
*-----------------------------------------------------------------------
form set_impm.
* dyn_ctlv-text      = 'Import from clipboard'(235).
* dyn_ctlv-icon_text =  space.

  if f_surnam = 'X'.
*   dyn_ctlv-icon_id = '@4P@'.
*   dyn_ctlv-qinfo   = 'Mark from clipboard by surname'(234).
    q_impm           = 'Mark by surname, click to change'(231).
    ps_impm          =  24.
  else.
*   dyn_ctlv-icon_id = '@2V@'.
*   dyn_ctlv-qinfo   = 'Mark from clipboard by username'(233).
    q_impm           = 'Mark by username, click to change'(232).
    ps_impm          =   8.
  endif.
endform. "SET_IMPM
*-----------------------------------------------------------------------
form set_mode_icon.
  if f_cmd_disable is initial.
    if f_cmd_mode is initial.
      if f_cmd_autoscan = 'X'.
        if f_cmd_autocrop = 'X'.
*         mode_icon =  icon_system_local_cut.
          mode_icon =  icon_filter.
*         q_mode    = 'Filter entries containing substring'(324).
        else.
*         mode_icon =  icon_search_next.
          mode_icon =  icon_set_copy_in_b.
*         q_mode    = 'Mark entries containing substring'(325).
        endif.
      else.
        mode_icon =  icon_extended_search.
*       q_mode    = 'Search entry containing substring'(326).
      endif.
    else.
*     mode_icon =  icon_execute_object.
*     mode_icon =  icon_message_warning_small.
*     mode_icon =  icon_message_warning.
      mode_icon =  icon_working_plan.
*     q_mode    = 'Process command'(327).
    endif.
  else.
    mode_icon =  icon_extended_search.
*   q_mode    = 'Search entry containing substring'(326).
  endif.

  mnew_icon = mode_icon.
endform. "SET_MODE_ICON
*-----------------------------------------------------------------------
form modify_mode_icon.
  perform set_mode_icon.

  read line 1.
  call function 'LIST_ICON_PREPARE_FOR_MODIFY'
       changing
         new_icon = mnew_icon
         .
  modify current line field value mode_icon from mnew_icon.
* modify line 1 field value mode_icon from mnew_icon.
endform. "MODIFY_MODE_ICON
*-----------------------------------------------------------------------
form toggle_docked.
  perform toggle_flag changing f_docked.

*-Set up output position PS_TB1
  perform set_ps_tb1.

  perform print_list_as_is.
endform. "TOGGLE_DOCKED
*-----------------------------------------------------------------------
form toggle_cmd_mode.
  perform toggle_flag changing f_cmd_mode.
  perform modify_mode_icon.
endform. "TOGGLE_CMD_MODE
*-----------------------------------------------------------------------
form toggle_cmdl.
  perform toggle_flag changing p_cmd.
  perform set_cmdl.
  perform print_table.
endform. "TOGGLE_CMDL
*-----------------------------------------------------------------------
form set_cmdl.
  if p_cmd = 'X'.
    cmdl_symb =  sym_left_triangle.
*   cmdl_icon =  icon_rating_minus.
*   cmdl_symb =  sym_left_arrow.
*   cmdl_symb =  sym_large_square.
*   cmdl_symb =  sym_filled_square.
*   cmdl_symb =  sym_filled_circle.
*   cmdl_symb =  sym_down_triangle.
*   cmdl_symb =  sym_down_arrow.
    q_cmdl    = 'Hide command line'(185).
  else.
    cmdl_symb =  sym_right_triangle.
*   cmdl_icon =  icon_rating_positive.
*   cmdl_symb =  sym_right_arrow.
*   cmdl_symb =  sym_checkbox.
*   cmdl_symb =  sym_square.
*   cmdl_symb =  sym_circle.
*   cmdl_symb =  sym_up_triangle.
*   cmdl_symb =  sym_up_arrow.
    q_cmdl    = 'Show command line'(186).
    clear: new_cmd, old_cmd, cmd.
  endif.
endform. "SET_CMDL
*-----------------------------------------------------------------------
form clear_cmdl.
  if not p_cmd is initial.
    clear cmd.
    modify line 1 field value cmd from cmd.
  endif.
endform. "CLEAR_CMDL
*-----------------------------------------------------------------------
form paste_cmdl.
  data:
    begin of it_cmd occurs 1
  ,   cmd(24)
  , end   of it_cmd
  .
  if p_cmd is initial. exit. endif.

  perform import_from_clipboard tables it_cmd.
  read table it_cmd index 1.
  if sy-subrc = 0.
*   move it_cmd-cmd to cmd.
    modify line 1 field value cmd from it_cmd-cmd.
  endif.
  if f_cmd_fastfind = 'X'. set_fcode 'OKAY'. endif.
endform. "PASTE_CMDL
*-----------------------------------------------------------------------
form do_header.  "PRINTS PAGE HEADER WHEN PF-STATUS IS SET TO 'MAIN'
* check sy-pfkey = 'MAIN'.
*-Prevent horizontal scrolling for this line
  new-line no-scrolling.

  if p_refr = 'X'.
    auto_symb = sym_check_mark.
    q_auto = 'Refresh-on-Return: Activated'(909).
  else.
    auto_symb = sym_bold_x.
    q_auto = 'Refresh-on-Return: Deactivated'(908).
  endif.

  write / auto_symb as symbol inverse quickinfo q_auto.

  perform set_cmdl.
  perform set_mode_icon.
*------------------------------------
  define upper_toolbar.
    ps_bar = sy-colno + 1.
    perform set_ps_tb1.
*   position ps_tb1.
    write at ps_tb1
      excl_icon as icon hotspot quickinfo text-321 "Exclude
    .
    perform put_keep.
    write:
*     at ps_tb1
*     rdev_icon as icon hotspot quickinfo text-064 "Jump to DEV
*   , rqas_icon as icon hotspot quickinfo text-065 "Jump to QAS
*   , rprd_icon as icon hotspot quickinfo text-066 "Jump to PRD
      crop_icon as icon hotspot quickinfo text-975 "Crop list
    , ctlc_icon as icon hotspot quickinfo text-898 "Copy to clipboard
    , ctlv_icon as icon hotspot quickinfo text-899 "Mark from clipboard
    , chck_icon as icon hotspot quickinfo q_chck   "F_CHKADDR 'Yes/No'
*   , rusr_icon as icon hotspot quickinfo text-930 "Jump to USR
    .
    perform put_aref.
*   write space.
  end-of-definition. "UPPER_TOOLBAR
*------------------------------------
  if p_cmd = 'X'.
    write:
      cmd color col_heading input no-gap
    , clea_icon as icon hotspot
    , past_icon as icon hotspot
    , mode_icon as icon hotspot
*       quickinfo q_mode
    , choo_icon as icon hotspot
        quickinfo 'Choose mode'(397)
    , area_icon as icon hotspot
        quickinfo q_area   "Search area Wide/Narrow
    , space
    ,     (03) 'Cli'(201)
    , p_mandt     color = hd0 input           "Client
    ,
*   at ps_sid(07)
      sy-sysid    color = hd0 inverse hotspot "SAP System Name (SID)
        quickinfo 'Show SAP licenses'(994)
    .
  else.
    write:
    (07) 'Client'(011)
    , p_mandt     color = hd0 input           "Client
    ,
*   at ps_sid(07)
                  'System'(020)
    , sy-sysid    color = hd0 inverse hotspot "SAP System Name (SID)
        quickinfo 'Show SAP licenses'(994)
    .
  endif.

  write:
*   at ps_rel(05)
             (05) 'Rel.'(021)
  , sy-saprl    color = hd0 inverse hotspot "SAP R/3 Release
      quickinfo 'Show SAP Release information'(993)
  ,
*   at ps_ker(06)
             (06) 'Kernel'(198)
  , kerninfo    color = hd0 inverse         "Kernel Info
*     quickinfo 'Kernel Release and Patch Level'(776)
*     quickinfo  q_kern
      quickinfo  kern_comp_time
  .
  write:
*   at ps_hst(09)
             (09) 'Hostname'(022)
  , sy-host     color = hd0 inverse         "Host name (32 chars max.)
      quickinfo  host_ip
  .
  if p_cmd is initial.
    write:
*   at ps_pla(09)
             (09) 'Platform'(034)
  , platform    color = hd0 inverse         "OS and DB names
  .
  endif.

*-Put Upper toolbar
  upper_toolbar.

  perform uline_main using c_top.

*-Compute TOP, CENTER and BOTTOM lines of a table header
  head_to = sy-linno.    " TOP    = sy-linno + 0.
  head_ce = head_to + 1. " CENTER = sy-linno + 1.
  head_bo = head_ce + 1. " BOTTOM = sy-linno + 2.

*-------- This is a small joke: roll colors when list resorted ---------
* if sy-datum+4(4) = '0401'.             "If date = '1 April'
*   add 1 to: c01, c02, c03, c04, c05, c06, c08, c09, c12, c13, c14.
*   add 1 to: c01, c02,      c04,      c06.
* endif.
*-----------------------------------------------------------------------

*-Set single mouse click equal to double
  if p_hot = 'X'. format hotspot on. endif.

  format color = hd1 intensified = hd1_in.  "Pale or bright colors
  write:                                    "Output field headers
  /  sy-vline
  , (12) 'User'(202)                        "Logon name
  ,  f_sele as checkbox input off hotspot
  ,  sy-vline                        no-gap
  .
  if p_scroll = 'X'.
    set left scroll-boundary.               "Nale down list here
  endif.

  write:
    qcpy_symb as symbol
       hotspot quickinfo q_qcpy      "o-gap
  , (13) 'Last name'(003)            no-gap "Last  name
  .
  write:
    (24) 'First name'(004)           no-gap "First name
  ,  sy-vline                        no-gap
  .
  if p_expand is initial.
    write
    (08) 'Phone'(005)                no-gap "Phone number (collapsed)
    .
  else.
    write
    (15) 'Phone'(005)                no-gap "Phone number (expanded)
    .
  endif.

  write:
     expa_symb as symbol
       hotspot quickinfo q_expa      no-gap
  ,  sy-vline                        no-gap
  , (05) 'Local'(006)                no-gap "Local phone
  ,  sy-vline                        no-gap
  , (40) 'Function'(008)             no-gap "Function
  ,  sy-vline                        no-gap
  , (40) 'Department'(013)           no-gap "Department
  ,  sy-vline                        no-gap
  , (07) 'Build.'(018)               no-gap "Building
  ,  sy-vline                        no-gap
  , (05) 'Room'(019)                 no-gap "Room number
  ,  sy-vline                        no-gap
  , (10) 'Last logon'(900)                  "Date   of last logon
  , (08) 'Time reg'(901)             no-gap "Time   of last logon
  ,  sy-vline                        no-gap
  , (12) 'Changed by'(027)                  "Author of modification
  , (10) 'Date'(028)                        "Date   of modification
  , (08) 'Time'(029)                 no-gap "Time   of modification
  ,  sy-vline                        no-gap
  , (12) 'Creator'(829)                     "Creator
  , (10) 'Creat.Date'(830)           no-gap "Creation date
  ,  sy-vline
  .
  perform uline_main using c_middle.
  perform put_sort_indicator.
endform. "DO_HEADER
*-----------------------------------------------------------------------
* To keep letter case unchanged here used WPTOTLICER-COM_ERROR (128)
* instead of SM04DIC-POPUPMSG (128)
form get_message using p_popup_title
                       p_add_tail
                       p_all_fields
              changing p_l_msg      like wptotlicer-com_error
                       p_l_man      like sy-mandt
                       p_l_dest     like msxxlist-name
                       p_returncode type c
                       .
  data v_tmp like fields-value.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  if p_add_tail = 'X'.
    concatenate p_l_msg '-' sy-uname
           into v_tmp
                separated by space
                .
  else. v_tmp = p_l_msg. endif.

  a_flds  msg_tabn           "SM04DIC
          msg_fldn           "POPUPMSG
         'Message text'(001) "Field caption (label)
          v_tmp
          .
  if p_all_fields = 'X'.
    a_flds 'T000'
           'MANDT'
           'Client'(011)     "Field caption (label)
            p_l_man
            .
    a_flds 'MSXXLIST'
           'NAME'
           'Server name'(788)
            p_l_dest
            .
  endif.

  call function 'POPUP_GET_VALUES_USER_HELP'
       exporting
         popup_title     =  p_popup_title
         f4_formname     = 'F4_HELP_POPUP'
         f4_programname  =  sy-cprog
       importing
         returncode      =  p_returncode
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.
  if p_returncode <> 'A'.
*---get message text entered by user
    r_flds 1 p_l_msg.

*---convert p_l_msg from Appl. Server code page to SAPGUI code page,
*   for instance, from 1500 (ISO-8859-5 UNIX Russian) to 1504 (Win-1251)

*   call function 'Z_APP2GUI' changing string = p_l_msg.
*   translate p_l_msg from code page cur_app_cp
*                       to code page cur_gui_cp.

    export last_msg from p_l_msg to memory id idxkey.
    if p_all_fields = 'X'.
*-----get mandant value entered by user
      r_flds 2 p_l_man.

*-----get sever value entered by user
      r_flds 3 p_l_dest.
    endif.
  endif.
  free fields.
endform. "GET_MESSAGE
*-----------------------------------------------------------------------
*form crash_warning using keepalive changing ans.
*  data textline2 like spop-textline2.
*  concatenate text-102 keepalive into textline2 separated by space.
*  clear ans.
**-Warning on probable crash of recipient sessions when timeout reached
**-This is correct for 'rdisp/gui_auto_logout' or 'rdisp/keepalive' > 0.
*  call function 'POPUP_TO_DECIDE'
*       exporting
*         defaultoption  = 2            "Set default to button 2
*         textline1      = text-101     "Your text line 1
*         textline2      = textline2    "Your text line 2
*         textline3      = text-103     "Your text line 3
*         text_option1   = text-104     "Button 1
*         text_option2   = text-105     "Button 2
*         titel          = text-100     "Popup title
*         start_column   = 10           "X-position on screen
*         start_row      =  5           "Y-position on screen
*         cancel_display = space        "space for hide 'CANCEL'
*       importing
*         answer         = ans          "Pressed button here
*         .
*endform. "CRASH_WARNING
*-----------------------------------------------------------------------
form get_user_server using v_mandt  like sy-mandt
                           v_bname  like sy-uname
                  changing v_server like msxxlist-name
                           .
  select server into v_server
                up to 1 rows
                from usr41 client specified
                where mandt = v_mandt
                  and bname = v_bname
                      .
  endselect.
  if sy-subrc <> 0. clear v_server. endif.
endform. "GET_USER_SERVER
*-----------------------------------------------------------------------
form send_popup_to_user using l_mandt like sy-mandt
                              l_bname like sy-uname
                              .
  data:
    l_popup_title(80)
  , l_ret
  , l_len  like sy-index
  , l_msg  like wptotlicer-com_error "Standard: SM04DIC-POPUPMSG
  , l_tmp  like l_msg
  , l_dest like msxxlist-name
  , comma  value ','
  .
*-Check for active ARFC calls
  check_arfc.

*-IMPORTANT!!!
* keepalive_check.

  perform get_user_server using l_mandt
                                l_bname
                       changing l_dest
                                .
*-Build popup title
  concatenate text-040 l_bname
         into l_popup_title
              separated by space
              .
*-Build salut using first name:
* first, read an internal table (faster!)
  read table it with key mandt = l_mandt
                         bname = l_bname
                         .
* then, if entry not found, read data from DB
  if sy-subrc <> 0.
    perform get_user_name
                    using l_mandt       l_bname
                 changing it-name_first it-name_last
                          .
  endif.

  if ( sy-subrc = 0 ) and ( not it-name_first is initial ).
    concatenate it-name_first comma into l_msg.
  else.
    concatenate l_bname       comma into l_msg.
  endif.
  condense l_msg.

  cls t_msglst.
*'authorizations were added. Please relogon into R/3 system.'
  concatenate l_msg text-795 into l_tmp separated by space.
  app_t_msglst l_tmp.
*'authorizations were added. It takes effect immediately.'
  concatenate l_msg text-796 into l_tmp separated by space.
  app_t_msglst l_tmp.

*-Request message text
  perform get_message
                using l_popup_title 'X' 'X'
             changing l_msg l_mandt l_dest l_ret
                      .
  if l_ret = 'A'.
    app_log_z2_0 '003'.
*--'Sending cancelled'
    message w003.
*   message w003(z2).                      "Equivalent variant
*   message id 'Z2' type 'W' number '003'. "Equivalent variant
*   exit.
  elseif fm_th_popup-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_th_popup-name.
*--'Called function module does not exist in the system &' + &V2&
    message s063 with sy-sysid fm_th_popup-name.
  else.
    l_len = strlen( l_msg ).
    if l_dest <> myname and not l_dest is initial.
*-----Send via RFC
      call function fm_th_popup-name
           destination        l_dest
           exporting
             client         = l_mandt
             user           = l_bname
             message        = l_msg
             message_len    = l_len
           exceptions
             user_not_found = 1
             others         = 99
             .
      case sy-subrc.
        when 0.
          app_log_z2_2 '000' l_bname l_mandt.
*--------'Message sent to user &1 in client &2'
          message s000  with l_bname l_mandt.
        when 1.
          app_log_z2_3 '070' l_bname l_mandt l_dest.
*--------'User &1 (&2) not found (server &3)'
          message e070  with l_bname l_mandt l_dest.
        when others.
          app_log_z2_1 '071' l_dest.
*--------'Communication error (server &1)'
          message e071 with l_dest.
      endcase.
    else.
*-----Send locally
      call function fm_th_popup-name
           exporting
             client         = l_mandt
             user           = l_bname
             message        = l_msg
             message_len    = l_len
           exceptions
             user_not_found = 1
             .
      if sy-subrc = 0.
        app_log_z2_2 '000' l_bname l_mandt.
*------'Message sent to user &1 in client &2'
        message s000  with l_bname l_mandt.
      else.
        app_log_z2_2 '004' l_bname l_mandt.
*------'User &1 in client &2 not found (inactive)'
        message e004  with l_bname l_mandt.
      endif.
    endif.
  endif.
endform. "SEND_POPUP_TO_USER
*-----------------------------------------------------------------------
form send_popup_single.
  get_and_check_sel_bname.
  perform send_popup_to_user using p_mandt sel_bname.
endform. "SEND_POPUP_SINGLE
*-----------------------------------------------------------------------
form send_popup.
  check_mark_exists.
  if sy-subrc = 0.
*---Mass POPUP
    cls it_rec.
    loop at it assigning <fs> where mark = 'X'.
      it_rec-client = <fs>-mandt.
      it_rec-bname  = <fs>-bname.
      perform get_user_server using it_rec-client
                                    it_rec-bname
                           changing it_rec-server
                                    .
      append it_rec.
    endloop.
    perform send_popup_mass tables it_rec.
  else.
*---Single POPUP
    perform send_popup_single.
  endif.
endform. "SEND_POPUP
*-----------------------------------------------------------------------
form send_popup_s.
  cls it_rec.
  loop at it41s assigning <fs2> where mark = 'X'.
    it_rec-client = <fs2>-mandt.
    it_rec-bname  = <fs2>-bname.
    it_rec-server = <fs2>-server.
    clear it_rec-rc.
    append it_rec.
  endloop.

  describe table it_rec lines sy-tfill.
  case sy-tfill.
    when 0.
*     read current line field value it41s-bname into sel_bname.
*     read current line field value it41s-mandt into mandt_s.
*     perform send_popup_single.
      get_and_check_sel_bname.
      perform send_popup_to_user using mandt_s sel_bname.

*   when 1.
    when others.
      perform send_popup_mass tables it_rec.
  endcase.
endform. "SEND_POPUP_S
*-----------------------------------------------------------------------
define app_mass_val.
  move &1 to mass_val-value. condense mass_val-value.
  append mass_val.
end-of-definition. "APP_MASS_VAL
*-----------------------------------------------------------------------
*orm log_failed.
* data:
*   failed_cnt(5)
* , v_title(40)
* , begin of mass_val occurs 10
* ,   value(20)
* , end   of mass_val
* .
* free t_fld.
*
* app_t_fld 'T000'     'MANDT'.
* app_t_fld 'USR02'    'BNAME'.
* app_t_fld 'MSXXLIST' 'NAME'.
* app_t_fld 'SYST'     'SUBRC'.
*
* loop at it_rec where rc <> 0.
*   app_mass_val it_rec-client.
*   app_mass_val it_rec-bname.
*   app_mass_val it_rec-server.
*   app_mass_val it_rec-rc.
*   add 1 to failed_cnt.
* endloop.
* condense failed_cnt.
* v_title = 'Errors during POPUP sending (&)'(977).
* replace amp with failed_cnt into v_title. condense v_title.
*
* call function 'POPUP_TO_SHOW_DB_DATA_IN_TABLE'
*      exporting
*        title_text        = v_title
*      tables
*        fields            = t_fld
*        valuetab          = mass_val
*      exceptions
*        field_not_in_ddic = 1
*        .
* check_wrong_fields.
* free t_fld.
*ndform. "LOG_FAILED
*-----------------------------------------------------------------------
define macro_alv_merge.
  cls gt_fieldcat.
  g_tabname_header = &1.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       exporting
         i_program_name         = g_repid
         i_internal_tabname     = g_tabname_header
         i_inclname             = g_repid
       changing
         ct_fieldcat            = gt_fieldcat[]
       exceptions
         inconsistent_interface = 1
         program_error          = 2
         .
  if sy-subrc <> 0.
    app_log_z2_2 '031' text-995 sy-subrc.
    message e031 with 'Field catalog merge error ='(995) sy-subrc.
  endif.
end-of-definition. "MACRO_ALV_MERGE
*-----------------------------------------------------------------------
define macro_alv_icon.
*-Display the field as icon
  read table gt_fieldcat with key fieldname = &1.
  if sy-subrc = 0.
    gt_fieldcat-icon         = 'X'.
    gt_fieldcat-seltext_l    =
    gt_fieldcat-seltext_m    =
    gt_fieldcat-seltext_s    =
    gt_fieldcat-reptext_ddic = &2.
    modify gt_fieldcat index sy-tabix.
  endif.
end-of-definition. "MACRO_ALV_ICON
*-----------------------------------------------------------------------
define macro_alv_field_title.
*-Set a title for the field (per instance, for detailed view)
  read table gt_fieldcat with key fieldname = &1.
  if sy-subrc = 0.
    gt_fieldcat-seltext_l    =
    gt_fieldcat-seltext_m    =
    gt_fieldcat-seltext_s    =
    gt_fieldcat-reptext_ddic = &2.
    modify gt_fieldcat index sy-tabix.
  endif.
end-of-definition. "MACRO_ALV_FIELD_TITLE
*-----------------------------------------------------------------------
define macro_alv_hide.
*-Hide the field
  read table gt_fieldcat with key fieldname = &1.
  if sy-subrc = 0.
    gt_fieldcat-no_out = 'X'.
    modify gt_fieldcat index sy-tabix.
  endif.
end-of-definition. "MACRO_ALV_HIDE
*-----------------------------------------------------------------------
define macro_alv_popup.
  gt_outtab[] = &7.

  call function 'REUSE_ALV_POPUP_TO_SELECT'
       exporting
         i_title                 =  alv_title
         i_selection             = ' '
         i_zebra                 =  &1
         i_screen_start_column   =  &2
         i_screen_start_line     =  &3
         i_screen_end_column     =  &4
         i_screen_end_line       =  &5
*        i_checkbox_fieldname    =
*        i_linemark_fieldname    =
*        i_scroll_to_sel_line    = 'X'
         i_tabname               =  &6
         it_fieldcat             =  gt_fieldcat[]
*        it_excluding            =
*        i_callback_program      =  g_repid
*        i_callback_user_command =
*        is_private              =  gs_private
*      importing
*        es_selfield             =  gs_selfield
*        e_exit                  =  g_exit
       tables
         t_outtab                =  gt_outtab
       exceptions
         program_error           =  1
         others                  =  2
         .
* free gt_outtab.
  if sy-subrc <> 0.
    app_log_z2_2 '031' text-996 sy-subrc.
    message e031 with 'ALV POPUP error ='(996) sy-subrc.
  endif.
end-of-definition. "MACRO_ALV_POPUP
*-----------------------------------------------------------------------
form log_failed_alv using value(v_only_err).
  data:
    gt_outtab like standard table of it_rec_alv with header line
  , failed_cnt(5)
  .
  refresh it_rec_alv.
  if v_only_err is initial.
    loop at it_rec.
      it_rec_alv-client = it_rec-client.
      it_rec_alv-bname  = it_rec-bname.
      it_rec_alv-server = it_rec-server.
      it_rec_alv-rc     = it_rec-rc.
      if it_rec-rc = 0.
        it_rec_alv-iconid = icon_ok.
      else.
        it_rec_alv-iconid = icon_failed.
        add 1 to failed_cnt.
      endif.
      append it_rec_alv.
    endloop.
  else.
    loop at it_rec where rc <> 0.
      it_rec_alv-client = it_rec-client.
      it_rec_alv-bname  = it_rec-bname.
      it_rec_alv-server = it_rec-server.
      it_rec_alv-rc     = it_rec-rc.
      it_rec_alv-iconid = icon_failed.
      append it_rec_alv.
    endloop.
    describe table it_rec_alv lines sy-tfill.
    move sy-tfill to failed_cnt.
  endif.

*-Set ALV title
  condense failed_cnt.
  alv_title = 'Errors during POPUP sending (&)'(977).
  replace amp with failed_cnt into alv_title. condense alv_title.

*-Build field catalog
  macro_alv_merge 'IT_REC_ALV'.

*-Display the field as icon
  macro_alv_icon 'ICONID' 'Res'(199).

*-Set a title for the field (for detailed view)
  macro_alv_field_title 'RC' 'RetCode'(997).

*-Hide the field
  macro_alv_hide 'RC'.

  macro_alv_popup 'X' 0 0 0 0 'IT_REC_ALV' it_rec_alv[].
endform. "LOG_FAILED_ALV
*-----------------------------------------------------------------------
* See source in MSLICF01, form SL_READ_DATA
form sl_read_data.
  data exp(8) type c.

  clear:
    licheck_entrys[]
  , license_table[]
  .
  call function 'SLIC_GET_CUSTKEY'
       exporting
         from_where =  1
         hostname   = ' '
       importing
         custkey    =  custkey
         .
* call function 'SLIC_GET_LICENCE_DATE'
*      importing
*        license_date = expirdate
*        .
  call 'GET_ACCESS_INFO'
    id 'CODE'               field get_license_expiration_date
    id 'LICENSE_EXPIRATION' field exp
    .
  expirdate = exp.

  call function 'SLIC_GET_LICENCE_NUMBER'
       importing
         license_number = instnr
         .
  call function 'SLIC_READ_LICENSES'
       importing
         count     = licensecount
       tables
         licenses  = licheck_entrys
       exceptions
         slicerror = 1
         others    = 2
         .
  if sy-subrc <> 0.
    app_log 'SLIC' '209' space space space space.
*--'Cannot read licenses'
    message s209(slic).
  else.
    loop at licheck_entrys.
      move-corresponding licheck_entrys to license_table.
      if    ( license_table-sysname        = sy-sysid )
        and ( license_table-custkey        = custkey  )
*       and ( license_table-productid+3(3) = sy-dbsys )
        .
*       license_table-active = 'X'.
        license_table-iconid =  icon_active.
      else.
*       license_table-active = ' '.
        license_table-iconid =  icon_inactive.
      endif.
      append license_table.
    endloop.
  endif.
endform. "SL_READ_DATA
*-----------------------------------------------------------------------
form show_licenses.
  data:
    gt_outtab    like standard table of license_table with header line
  , alv_end_line like sy-curow
  .
*-Set ALV title
  alv_title = 'Installed SAP licenses (saplicense -show)'(991).

*-Build field catalog
  macro_alv_merge 'LICENSE_TABLE'.

*-Display the field as icon
  macro_alv_icon 'ICONID' 'Act'(860).

*-Set titles for the fields
  macro_alv_field_title 'SYSNAME'   'System'(020).
  macro_alv_field_title 'USERLIMIT' 'User limit'(992).

  describe table license_table lines sy-tfill.
  alv_end_line = sy-tfill + 7.

  macro_alv_popup
    ' ' 5 5 107 alv_end_line 'LICENSE_TABLE' license_table[].
endform. "SHOW_LICENSES
*-----------------------------------------------------------------------
form fill_it_extra.
* check p_extra = 'X'.
* perform get_thusrinfo.
* perform count_extra.
  cls it_extra.
* clear: rfc_cnt, zombie_cnt, others_cnt.

  loop at it_th.
*---Copy all corresponding values
    move-corresponding it_th to it_extra.
    case it_th-rfc_type.
      when 'E'.    move '@BW@'              to it_extra-iconid.
                   move 'External RFC'(139) to it_extra-iconid_info.
      when 'I'.    move '@5B@'              to it_extra-iconid.
                   move 'Internal RFC'(140) to it_extra-iconid_info.
      when others. move '@CZ@'              to it_extra-iconid.
                   move it_th-rfc_type      to it_extra-iconid_info.
    endcase.
*---Describe connection type
    case it_th-type.
      when   4.    move 'GUI   '(853)       to it_extra-type_txt.
      when  32.    move 'RFC   '(854)       to it_extra-type_txt.
*                  add 1 to rfc_cnt.
      when 202.    move 'Plugin'(855)       to it_extra-type_txt.
*                  add 1 to others_cnt.
      when others. move  it_th-type         to it_extra-type_txt.
*                  add 1 to others_cnt.
    endcase.
*---Describe connection status
    case it_th-stat.
      when   2.    move 'Connected'(856)    to it_extra-stat_txt.
                   move  col_normal         to it_extra-stat_col.
      when   4.    move 'Zombie   '(857)    to it_extra-stat_txt.
                   move  col_negative       to it_extra-stat_col.
*                  add 1 to zombie_cnt.
      when   6.    move 'Pooled   '(858)    to it_extra-stat_txt.
                   move  col_group          to it_extra-stat_col.
      when others. move  it_th-stat         to it_extra-stat_txt.
                   move  col_total          to it_extra-stat_col.
    endcase.
*---If user has no authority to read system traces or the flag P_NO_IP
*   is set ON, then remove IP-Address part from TERMINAL
    if auth_st0r is initial or p_no_ip = 'X'.
      it_extra-ip_addr = '*** hidden! ***'(138).
    else.
*-----Convert IP address from hex to readable view
      perform convert_hostadr using it_th-hostadr
                           changing it_extra-ip_addr
                                    .
    endif.

*---Append entry
    append it_extra.
  endloop.
endform. "FILL_EXTRA
*-----------------------------------------------------------------------
form convert_hostadr using value(v_hostadr) like it_th-hostadr
                  changing value(v_ip_addr) like it_extra-ip_addr
                           .
  data:
    i_tmp type i
  , s_ip_1(3)
  , s_ip_2(3)
  , s_ip_3(3)
  , s_ip_4(3)
  , dot value '.'
  .
*-Convert IP address from hex to readable view
  move v_hostadr+0(1) to i_tmp. move i_tmp to s_ip_1.
  move v_hostadr+1(1) to i_tmp. move i_tmp to s_ip_2.
  move v_hostadr+2(1) to i_tmp. move i_tmp to s_ip_3.
  move v_hostadr+3(1) to i_tmp. move i_tmp to s_ip_4.

  concatenate s_ip_1 s_ip_2 s_ip_3 s_ip_4
         into v_ip_addr
              separated by dot
              .
  condense v_ip_addr no-gaps.
endform. "CONVERT_HOSTADR
*-----------------------------------------------------------------------
define check_auth_sm02.
*-If user has no authority to create system messages
  if auth_sm02 is initial.
    app_log_00_0 '699'.
*--'No authorization to create, change or delete system messages'
    message e699(00).
*--'You haven't authorization for object &'
*   message e149(00) with obj_sysadm.
*   exit.
  endif.
end-of-definition. "CHECK_AUTH_SM02
*-----------------------------------------------------------------------
form send_popup_mass tables it_rec structure st_it_rec.
  data:
    l_popup_title(80)
  , l_ret
  , l_ret2
  , f_add_tail
  , l_msg      like wptotlicer-com_error "Standard: SM04DIC-POPUPMSG
  , h_msg      like l_msg
  , e_cnt      type i
  , s_cnt      type i
  .
  check_auth_sm02.

*-Check for active ARFC calls
  check_arfc.

*-IMPORTANT!!!
* keepalive_check.

*-Remove duplicates
  sort it_rec by client bname server ascending.
  delete adjacent duplicates from it_rec comparing client bname server.

  describe table it_rec lines sy-tfill.
  case sy-tfill.
    when 0.
      app_log 'SO' '761' space space space space.
*----'Please select at least one recipient'
      message w761(so).

    when 1.
      read table it_rec index 1.
*-----Build popup title
      concatenate text-040 it_rec-bname
             into l_popup_title
                  separated by space
                  .
*-----Build salut using first name:
*     first, read an internal table (faster!)
      read table it with key mandt = it_rec-client bname = it_rec-bname.
*     then, if entry not found, read data from DB
      if sy-subrc <> 0.
        perform get_user_name
                        using it_rec-client it_rec-bname
                     changing it-name_first it-name_last
                              .
      endif.

      if ( sy-subrc = 0 ) and ( not it-name_first is initial ).
        concatenate it-name_first ',' into l_msg.
      else.
        concatenate it_rec-bname  ',' into l_msg.
      endif.
      condense l_msg.
    when others.
      l_popup_title = 'Mass popup sending (&)'(976).
      move sy-tfill to cnt. condense cnt.
      replace amp with cnt into l_popup_title.
      condense l_popup_title.
  endcase.

  f_add_tail = 'X'.
  while l_ret <> 'A'.

*---Build message pattern
    cls t_msglst.
    perform system_shutdown_message changing h_msg.
    app_t_msglst h_msg.


*---Request message text
    perform get_message
                  using l_popup_title f_add_tail space
               changing l_msg
                        it_rec-client
                        it_rec-server
                        l_ret
                        .
    if l_ret = 'A'.
      app_log_z2_0 '003'.
*----'Sending cancelled'
      message w003.
    else.
      perform confirm_mass_sending using l_msg space
                                changing l_ret2
                                         .
      if l_ret2 = 'Y'.
        l_ret = 'A'.
        if fm_th_pop_m-exists is initial.
*         app_log 'FL' '110' fm_th_pop_m-name space space space.
*--------'Function module & does not exist'
*         message i110(fl) with fm_th_pop_m-name.
          app_log_z2_2 '063' sy-sysid fm_th_pop_m-name.
*--------'Called function module does not exist in the system &' + &V2&
          message i063 with sy-sysid fm_th_pop_m-name.
        else.
          call function fm_th_pop_m-name
               exporting
                 message  = l_msg
               tables
                 user_tab = it_rec
                 .
          describe table it_rec lines sy-tfill.
          move sy-tfill to s_cnt. clear e_cnt.

          loop at it_rec where rc <> 0.
            add 1 to e_cnt. subtract 1 from s_cnt.
          endloop.
          if e_cnt = 0.
            app_log 'FE' '602' s_cnt space space space.
*----------'Message was sent to & recipients'
            message s602(fe) with s_cnt.
          else.
            if s_cnt > 0.
              app_log_z2_2 '089' s_cnt e_cnt.
*------------'Succesfully sent: &, errors: &'
              message i089 with s_cnt e_cnt.
              perform log_failed_alv using ' '.
            else.
              perform log_failed_alv using 'X'.
            endif.
          endif.
        endif.
      else.
*-------Prevent double-tail :-)
        clear f_add_tail.
      endif.
    endif.
  endwhile.
endform. "SEND_POPUP_MASS
*-----------------------------------------------------------------------
form confirm_mass_sending using value(v_msg)
                                value(v_comment)
                       changing p_ret2
                                .
  data:
    l_len         like sy-index
  , l_dif         like l_len
  , c_lim         like l_len      value 75
  , l_message1(80)
  , l_message2    like l_message1
  , l_comment     like l_message1
  , l_icon        type icon_d     value '@AI@' " ICON_HINT
*                 type nav_iconid
  .
  data: begin of t_lines occurs 3.
          include structure popuptext.
  data: end   of t_lines.

  cls t_lines. clear: l_message1, l_message2.

  l_len = strlen( v_msg ).
  if l_len > c_lim.
    l_dif      = l_len - c_lim.
    l_message1 = v_msg(c_lim).
    l_message2 = v_msg+c_lim(l_dif).
  else.
    l_message1 = v_msg.
  endif.
  concatenate l_icon l_message1
         into l_message1
              separated by space
              .
  define app_t.
    t_lines-hell      = ' '.
    t_lines-topofpage = 'X'.
    t_lines-text      = &1.
    append t_lines.
  end-of-definition. "APP_T

  app_t  space.
  app_t  l_message1.

  if not l_message2 is initial.
    concatenate l_icon l_message2 into l_message2 separated by space.
    app_t  l_message2.
  endif.

  if not v_comment is initial.
    concatenate l_icon v_comment  into l_comment  separated by space.
    app_t  l_comment.
  endif.

  app_t  space.
  app_t '@1C@Send this message to users'(786).

  call function 'DD_POPUP_WITH_INFOTEXT'
       exporting
         titel        = 'Confirm multiple sending'(787)
         start_column =  20
         start_row    =   5
         end_column   = 100
         end_row      =  10
         infoflag     = ' '
       importing
         answer       =  p_ret2
       tables
         lines        =  t_lines
         .
endform. "CONFIRM_MASS_SENDING
*-----------------------------------------------------------------------
form system_shutdown_message changing v_msg.
  data t like sy-uzeit.

*-Build message pattern using current time + 30 minutes
*'After &system & will not be available'
  move text-038 to v_msg.
  move sy-uzeit to t. add 1800 to t.    "t = current time + 1800 sec.
  write t using edit mask t_mask to t.  "t now like '__:__:' (truncated)
  concatenate t(4) '0' into t.          "t    <-    '__:_' + '0'
  replace amp with     t    into v_msg. "Insert time X into message
  replace amp with sy-sysid into v_msg. "Insert SID into message
  condense v_msg.
endform. "SYSTEM_SHUTDOWN_MESSAGE
*-----------------------------------------------------------------------
form send_broadcast_popup_msg.
  data:
    l_man         like sy-mandt
  , l_len         like sy-index
  , l_comment(75)
  , l_ret
  , l_ret2
  , f_add_tail
  , sum_sent      type i
  , l_msg         like wptotlicer-com_error
  , l_dest        like msxxlist-name
  .
  check_auth_sm02.

*-IMPORTANT!!!
* keepalive_check.

  move: p_mandt to l_man
      , myname  to l_dest
      .
*-Build message pattern
  perform system_shutdown_message changing l_msg.

  f_add_tail = 'X'.
  while l_ret <> 'A'.
    cls t_msglst.
*---Request message text using previously assembled pattern
    perform get_message
                  using text-042 f_add_tail 'X'
               changing l_msg l_man l_dest l_ret
                        .
    if l_ret = 'A'.
      app_log_z2_0 '003'.
*----'Sending cancelled'
      message w003.
*     exit.
    elseif fm_th_popup-exists is initial.
*----'Called function module does not exist in the system &
      message s063 with sy-sysid fm_th_popup-name.
    else.
      concatenate 'Destination: client'(793) l_man
                            'on server'(794) l_dest
             into  l_comment
                   separated by space
                   .
      perform confirm_mass_sending using l_msg l_comment
                                changing l_ret2
                                         .
      if l_ret2 = 'Y'.
        l_ret = 'A'.
        clear sum_sent.                  "Reset message counter
        perform get_activity.            "Fresh info about active users

        if l_dest <> myname and not l_dest is initial.
          loop at it assigning <fs>
                  where online = 'X'        "To all founded users
                        .
            call function fm_th_popup-name
                 destination        l_dest
                 exporting
                   client         = l_man
                   user           = <fs>-bname
                   message        = l_msg
                   message_len    = l_len
*                  cut_blanks     = space
                 exceptions
                   user_not_found = 1
                   others         = 99
                   .
            if sy-subrc = 0. add 1 to sum_sent. endif.
          endloop.
          if sum_sent is initial.
            app_log_z2_2 '072' l_man l_dest.
*----------'No users were found in client &1 on server &2'
            message e072 with l_man l_dest.
          else.
            app_log_z2_3 '073' sum_sent l_man l_dest.
*----------'Message was sent to &1 users (&2) &3'
            message s073 with sum_sent l_man l_dest.
          endif.
        else.
          loop at it assigning <fs>
                  where online = 'X'        "To all founded users
                        .
            call function fm_th_popup-name
                 exporting
                   client         = l_man
                   user           = <fs>-bname
                   message        = l_msg
                   message_len    = l_len
*                  cut_blanks     = space
                 exceptions
                   user_not_found = 1
                   .
            if sy-subrc = 0. add 1 to sum_sent. endif.
          endloop.
          if sum_sent is initial.
            app_log_z2_1 '009' l_man.
*----------'No users were found in client &1'
            message e009 with l_man.
          else.
            app_log_z2_2 '010' sum_sent l_man.
*----------'Message was sent to &1 users in client &2'
            message s010 with sum_sent l_man.
          endif.
        endif.
      else.
*-------Prevent double-tail :-)
        clear f_add_tail.
      endif.
    endif.
  endwhile.
endform. "SEND_BROADCAST_POPUP_MSG
*-----------------------------------------------------------------------
form get_bname.
* REMEMBER!   sy-lisel+i(n) <==> Copy(sy_lisel,i,n) in Pascal
*             n chars from position i of whole selected line
  case sy-pfkey.
    when 'MAIN'.
      if sy-curow gt head_bo and       "If relative line > HEAD_RO and
         sy-lilli le last_ln.          "  absolute line inside of list
*       sel_bname = sy-lisel+2(12).    "Copy from output list
        move it-bname to sel_bname.
      else. clear sel_bname. endif.

    when 'SESS'.
      if sy-curow gt head_bo_s and     "If relative line > HEAD_RO_S and
         sy-lilli le last_ln_s.        "  absolute line inside of list
*       sel_bname = sy-lisel+7(12).    "Copy from output list
*       mandt_s   = sy-lisel+3(3).
        move:
          it41s-bname to sel_bname
        , it41s-mandt to mandt_s
        .
      elseif p_extra = 'X'.
        read current line field value it_extra-mandt into mandt_s.
        read current line field value it_extra-bname into sel_bname.
        if sy-subrc <> 0. clear sel_bname. endif.
      else.
        clear sel_bname.
      endif.

    when others.
      clear sel_bname.
  endcase.
endform. "GET_BNAME
*-----------------------------------------------------------------------
form get_remote_server changing dest_rem like msxxlist-name.
  if sy-pfkey = 'SESS'.
    if sy-curow gt head_bo_s and       "If relative line > HEAD_RO_S and
       sy-lilli le last_ln_s.          "  absolute line inside of list
      move it41s-server to dest_rem.
    else. clear dest_rem. endif.
  endif.
endform. "GET_REMOTE_SERVER
*-----------------------------------------------------------------------
form goto_server using dest_rem like msxxlist-name.
  if dest_rem is initial. select_valid_line. endif.

*-Check for active ARFC calls
  check_arfc.

  if dest_rem = myname.
    app_log_z2_2 '031' text-785 dest_rem.
    message s031 with 'You are already logged on server'(785) dest_rem.
  else.
    confirm_step 'Y'
                 'Do you want to continue with server'(783)
                  dest_rem
                 'Go to remote server'(784)
                  .
    case ans.
      when 'J'. perform remote_transaction using r_tcode dest_rem.
    endcase.
  endif.
endform. "GOTO_SERVER
*-----------------------------------------------------------------------
form goto_remote_server.
*-Check for active ARFC calls
  check_arfc.

  perform get_remote_server changing dest_rem.
  perform goto_server using dest_rem.
endform. "GOTO_REMOTE_SERVER
*-----------------------------------------------------------------------
form goto_given_remote_server.
  data tmp_dest like msxxlist-name.

*-Check for active ARFC calls
  check_arfc.

  call function 'POPUP_TO_GET_VALUE'
       exporting
         fieldname           = 'NAME'
         tabname             = 'MSXXLIST'
         titel               = 'RFC-jump to:'(931)
         valuein             =  usr_dest
       importing
         answer              =  ans
         valueout            =  tmp_dest
       exceptions
         fieldname_not_found =  1
         .
  if sy-subrc = 0 and ans = space.
    move tmp_dest to usr_dest.
    if not usr_dest is initial.
      perform remote_transaction using r_tcode usr_dest.
    endif.
  endif.
endform. "GOTO_GIVEN_REMOTE_SERVER
*-----------------------------------------------------------------------
form show_user_details using v_mandt like sy-mandt
                             v_bname like sy-uname
                             .
  if not fm_personal-exists is initial and v_mandt = sy-mandt.
    call function fm_personal-name
         exporting
           bname  = v_bname
         exceptions
           others = 1
           .
    if sy-subrc <> 0. show_details v_bname v_mandt. endif.
  else. show_details v_bname v_mandt. endif.
endform. "SHOW_USER_DETAILS
*-----------------------------------------------------------------------
* See original source in LPRGN_TREEF1F
form popup_user_display_addr using v_uname like sy-uname.
  data:
    s_bapiret2 like bapiret2
  , user       like bapibname-bapibname
  .
*-Check for active ARFC calls
  check_arfc.

  user = v_uname.
  call function 'BAPI_USER_DISPLAY'
       exporting
         username = user
       importing
         return   = s_bapiret2
         .
  if s_bapiret2-id <> ''.
    message id s_bapiret2-id type 'I' number s_bapiret2-number
       with s_bapiret2-message_v1.
  endif.
endform. "POPUP_USER_DISPLAY_ADDR
*-----------------------------------------------------------------------
form display_user_auths using value(v_bname) like sy-uname.
  if expert = 'X'.
    clear ans.
    call function 'POPUP_TO_DECIDE'
         exporting
           defaultoption     =  1
           textline1         = 'Please choose:'(878)
           textline2         = 'SUSR_USER_DISPLAY_WITH_AUTHS'
           textline3         = 'SUSR_USER_DISPLAY_WITH_S_TCODE'
           text_option1      = 'With AUTHS'(879)
           text_option2      = 'With S_TCODE'(880)
           icon_text_option1 = 'ICON_LAYOUT_CONTROL'
           icon_text_option2 = 'ICON_DISPLAY_TREE'
           titel             = 'Display authorizations'(881)
           start_column      =  25
           start_row         =  6
           cancel_display    = 'X'
         importing
           answer            =  ans
           .
    case ans.
      when '1'.    perform user_display_with_auths   using v_bname.
      when '2'.    perform user_display_with_s_tcode using v_bname.
*     when 'A'.
      when others. perform action_cancelled.
    endcase.
  else.
    perform user_display_with_auths using v_bname.
  endif.
endform. "DISPLAY_USER_AUTHS
*-----------------------------------------------------------------------
form user_display_with_auths using value(v_bname) like sy-uname.
  save_titlebar.
  set_titlebar_002.
  call function 'SUSR_USER_DISPLAY_WITH_AUTHS'
       exporting
         user              = v_bname
       exceptions
         user_doesnt_exist = 1
         .
  if sy-subrc <> 0.
*---Restore previous titlebar if any error occured
    restore_titlebar.
*   set_titlebar_001.
    app_log '01' '124' v_bname space space space.
*--'User & does not exist'
    message i124(01) with v_bname.
  endif.
endform. "USER_DISPLAY_WITH_AUTHS
*-----------------------------------------------------------------------
form user_display_with_s_tcode using value(v_bname) like sy-uname.
  data v_repid like sy-repid value 'RSUSR008'.

  set pf-status 'TREE_S_T' of program v_repid.
* set titlebar  'TR_'      of program v_repid.
  save_titlebar.
  set_titlebar_002.

  call function 'SUSR_USER_DISPLAY_WITH_S_TCODE'
       exporting
         user              = v_bname
       exceptions
         user_doesnt_exist = 1
         .
  if sy-subrc <> 0.
*---Restore previous titlebar if any error occured
    restore_titlebar.
*   set_titlebar_001.
    app_log '01' '124' v_bname space space space.
*--'User & does not exist'
    message i124(01) with v_bname.
  endif.
endform. "USER_DISPLAY_WITH_S_TCODE
*-----------------------------------------------------------------------
define check_padm.
*-If user has no authority to process administration
  if auth_padm is initial.
*   app_log_00_1 '149' obj_sysadm.
**-'You haven't authorization for object &'
*   message e149(00) with obj_sysadm.
    app_log_00_0 '433'.
*--'No authorization for process/program administration'
    message e433(00).
*   message e104(14). " <--This message is equal to e433(00)
*   exit.
  endif.
end-of-definition. "CHECK_PADM
*-----------------------------------------------------------------------
form show_user_activity.
* check_padm.
  get_and_check_sel_bname.

* if expert is initial.
*   set pf-status 'USER' excluding 'SEND'.
* else.
    set pf-status 'USER'.
* endif.
  set_titlebar_001.
  perform show_long_usr_info.
endform. "SHOW_USER_ACTIVITY
*-----------------------------------------------------------------------
form show_user_activity_rfc.
* check_padm.

  move:
    it_extra-mandt to mandt_s
  , it_extra-bname to sel_bname
  .
  if sel_bname is initial.
    app_log_00_0 '301'.
*--'Position the cursor on a line in the list'
    message e301(00).
*   message e001.                  "Place cursor at correct line
    exit.
  endif.

* if expert is initial.
*   set pf-status 'USER' excluding 'SEND'.
* else.
    set pf-status 'USER'.
* endif.
  set_titlebar_001.
  perform show_long_usr_info.
endform. "SHOW_USER_ACTIVITY_RFC
*-----------------------------------------------------------------------
data col_waste type i.                   "Color for wastetime
form write_time_part using xx txt.
  if xx = '00'. exit. endif.
  write: xx color = col_waste inverse no-gap, txt inverse no-gap.
endform. "WRITE_TIME_PART
*-----------------------------------------------------------------------
form smart_show_long_usr_info.
  perform back_if_detail. perform show_long_usr_info.
endform. "SMART_SHOW_LONG_USR_INFO.
*-----------------------------------------------------------------------
constants:
*-for SAP R/3 Release 4.6C
  i1         type i    value 112   "Underline width for terminals
, i2         like i1   value 121   "Underline width for transactions
*-for SAP R/3 Enterprise (4.7)
* i1         type i    value 132   "Underline width for terminals
* i2         like i1   value 123   "Underline width for transactions
.
data:
  fail_subrc like sy-subrc
, inv        type i
.
form show_long_usr_info.
  constants:
    cl_term_head value col_heading   "Terminals:    header
  , cl_term      value col_total     "Terminals:    list
  , cl_my_tid    value col_positive  "My terminal ID
  , cl_tran_head value col_heading   "Transactions: header
  , cl_tran      value col_normal    "Transactions: list
  .
  tables ush02.

  data:
    begin of h occurs 0
  ,   modda  like ush02-modda
  ,   modti  like ush02-modti
  ,   modbe  like ush02-modbe
  ,   tcode  like ush02-tcode
  , end   of h

  , pwd_days type i
  , s_modda(10)
  , s_modti(8)
  , q_ush02  like rsmpe_txt-quickinfo

  , st_newmod(50)
  , ln_newmod type i
  , v_objt    like tobjt-ttext
  , v_repid   like sy-repid
  , q_source  like rsmpe_txt-quickinfo
  , q_usfilt  like rsmpe_txt-quickinfo
  , q_userbtn like rsmpe_txt-quickinfo
  , q_uagr    like rsmpe_txt-quickinfo
  , f_multi
  , cl_tid    type i
  , u1        type i

  , begin of it_total occurs 10
  ,   page    like ublks-page
  ,   roll    like ublks-roll
  ,   memsum  like ublks-memsum
  ,   privsum like ublks-privsum
  , end   of it_total

  , wa  like line of usr_btabl
  , wa1 like line of it_total
  .
*--------------------------------------
  define put_checked_icon.
    write:
       icon_checked as icon
    ,  space
    , (16) 'Password changed'(349)
    .
  end-of-definition. "PUT_CHECKED_ICON
*-------------------------------------
  define put_pwdinfo.
    format color col_normal inverse.
    write:
    /2'@1T@Last Logon (all clients, date/time in descending order)'(964)
    ,  /
    .
    select * from usr02
             client specified
             where bname = sel_bname
             order by trdat descending
                      ltime descending
                      .
      write:
      /2 usr02-mandt color col_heading
      ,  usr02-ltime color col_heading
      ,  usr02-trdat color col_heading
      .
*     hide usr02-mandt.
*     write icon_display as icon hotspot. "Show history from USH02
      case usr02-ustyp.
        when 'B'.
*---------System
          write:
             icon_transfer                as icon
          , 'B-type: Dialog-free communications within one system'(224)
          .
          if not usr02-trdat is initial. put_checked_icon. endif.

        when 'C'.
*---------Communication
          write:
             icon_relation                as icon
          , 'C-type: Dialog-free communications between systems'(225)
          .
          if not usr02-trdat is initial. put_checked_icon. endif.

        when others.
*---------Dialog, Link, Service
          if usr02-trdat is initial and usr02-ltime is initial.
            write:
               icon_message_error_small   as icon quickinfo
*             'User had never been logged on into this client!'(965)
              'Account had not been used in the client!'(350)
            ,  space
            , (16) 'Password changed'(349)
            .
          elseif usr02-ltime is initial.
            write:
               icon_message_warning_small as icon
            ,  space
*           , 'Password for this user was probably reset?'(966)
            , (16) 'Password reset?'(348)
            .
          else. put_checked_icon. endif.

      endcase.
      if usr02-bcda1 is initial.
*       write 'Password has never been changed'(343).
        write '--.--.----'(347).
      else.
        clear h[].
        select
*              modda "cause only change documents to USR02-BCDA1 date
               modti
               modbe
               tcode
               from ush02 client specified
               into corresponding fields of table h
               where mandt = usr02-mandt
                 and bname = usr02-bname
                 and modda = usr02-bcda1
                     .
        if not h[] is initial.
          sort h by modda modti descending.
          read table h index 1.
          write usr02-bcda1 to s_modda using edit mask d_mask.
*         write h-modda     to s_modda using edit mask d_mask.
          write h-modti     to s_modti using edit mask t_mask.
          concatenate s_modda s_modti h-modbe h-tcode
                 into q_ush02
                      separated by space
                      .
        else.
          q_ush02 = 'Date of last password change'(345).
        endif.

        pwd_days = sy-datum - usr02-bcda1.
        write:
*         'Password has been changed on'(344)
           usr02-bcda1 quickinfo q_ush02
        ,  pwd_days
        , 'days past'(346)
        .
      endif.
    endselect.

    format color = cl_term intensified = intens inverse off.
  end-of-definition. "PUT_PWDINFO
*-------------------------------------
  if f_userbtn = 'X'.
    ubtn_symb =  sym_left_triangle.  "sym_checkbox.
    q_userbtn = 'Hide additional buttons'(166).
    u1 = i1 + 19.
    if f_ar is initial.
      uagr_icon =  icon_activity_group.
      q_uagr    = 'Display Z-roles assigned to user'(229).
    else.
      uagr_icon =  icon_generate.
      q_uagr    = 'Display all roles assigned to user'(164).
    endif.
  else.
    ubtn_symb =  sym_right_triangle. "sym_large_square.
    q_userbtn = 'Show additional buttons'(167).
    u1 = i1.
  endif.

  if p_usfilt = 'X'.
    filt_icon =  icon_presence.
    q_usfilt  = 'Filter for SM50, SM04, SM12 is ON'(939).
  else.
    filt_icon =  icon_absence.
    q_usfilt  = 'Filter for SM50, SM04, SM12 is OFF'(940).
  endif.

  clear f_multi.
  write / sy-uline(u1).
  format color = cl_term_head intensified = intens.
  write:
  /  sy-vline                                    no-gap
  , (03) 'Cli'(201)                              no-gap
  ,  sy-vline                                    no-gap
* ,  ubtn_symb as symbol
*      hotspot quickinfo q_userbtn
  ,  filt_icon as icon
       hotspot quickinfo q_usfilt
* ,  f_userbtn as checkbox input off
  , (12) 'User'(202)                             "o-gap
  ,  ubtn_symb as symbol                         no-gap
       hotspot quickinfo q_userbtn
  ,  sy-vline                                    no-gap
  .
  if f_userbtn = 'X'.
    write:
     send_head as icon
  ,  uadr_head as icon
  ,  uagr_head as icon
  ,  auth_head as icon
  ,  u010_head as icon
  ,  u100_head as icon
  ,  sy-vline                                    no-gap
  .
  endif.

  write:
    (36) 'IP-address - Terminal name'(044)       no-gap
  ,  sy-vline                                    no-gap
  , (10) 'Term.ID'(045)                          no-gap
  ,  sy-vline                                    no-gap
*-for SAP Release 4.6C
  , (20) 'Server'(046)                           no-gap
*-for SAP R/3 Enterprise (4.7)
* , (40) 'Server'(046)                           no-gap
  ,  sy-vline                                    no-gap
  , (10) 'Logon Date'(168)                       no-gap
  ,  sy-vline                                    no-gap
  , (08) 'Log.Time'(169)                         no-gap
  ,  sy-vline                                    no-gap
  .
  perform put_aref.
  perform put_aref_updown.
* format color col_normal inverse.
  write / sy-uline(u1).
  format color = cl_term intensified = intens inverse off.

* perform issue_select.
  select * from usr41 client specified where bname = sel_bname.
    write:
    / sy-vline       no-gap
    , usr41-mandt    no-gap "nder 'Cli'(201)
    , sy-vline       no-gap
*   , spoo_icon             under f_userbtn
*   , spoo_icon             under ubtn_symb
    , spoo_icon             under filt_icon
        as icon
        hotspot quickinfo 'Display spool requests'(161)
    , usr41-bname           "nder 'User'(202)
*       hotspot
                quickinfo 'Maintain user'(159)
    , ubtn_symb
        as symbol
        under ubtn_symb
        no-gap
        hotspot quickinfo q_userbtn
*       color col_total intensified inverse
*   , space          no-gap
    , sy-vline       no-gap
    .
    if f_userbtn = 'X'.
      write:
        send_icon      under send_head
          as icon
          hotspot quickinfo 'Send message'(160)
      , uadr_icon      under uadr_head
          as icon
          hotspot quickinfo 'Display user address data'(158)
      , uagr_icon      under uagr_head
          as icon
          hotspot quickinfo q_uagr
      .
      if usr41-mandt = sy-mandt.
        write:
          auth_icon
            as icon      under auth_head
            hotspot quickinfo 'Display authorization tree'(165)
        , u010_icon
            as icon      under u010_head
            hotspot quickinfo 'Display allowed transactions'(171)
        , u100_icon
            as icon      under u100_head
            hotspot quickinfo 'Go to change documents'(172)
        .
      else.
        write:
          icon_wf_workitem_cancel
*         icon_space
*         icon_dummy
            as icon      under auth_head
        , icon_wf_workitem_cancel
            as icon      under u010_head
        , icon_wf_workitem_cancel
            as icon      under u100_head
        .
      endif.
      write sy-vline                     no-gap.
    endif.
*---If user has no authority to read system traces
*   then remove IP-Address part from TERMINAL
    if auth_st0r is initial.
      split usr41-terminal at '-' into usr41-terminal usr41-terminal.
    endif.

    if usr41-server = myname.
      if usr41-bname = sy-uname and usr41-termid = my_tid.
        cl_tid = cl_my_tid.
      else.
        cl_tid = cl_term.
      endif.

      write:
        usr41-terminal no-gap                "nder text-044
      , sy-vline       no-gap
      , usr41-termid   no-gap color = cl_tid "nder text-045
      , sy-vline       no-gap
*-----for SAP R/3 Release 4.6C
      , usr41-server   no-gap                "nder text-046
*-----for SAP R/3 Enterprise (4.7) - with restricted output length
*, (20) usr41-server   no-gap                "nder text-046
      .
    else.
      f_multi = 'X'.
      write:
        usr41-terminal no-gap inverse        "nder text-044
      , sy-vline       no-gap
      , usr41-termid   no-gap inverse        "nder text-045
      , sy-vline       no-gap
*-----for SAP R/3 Release 4.6C
      , usr41-server   no-gap inverse        "nder text-046
*-----for SAP R/3 Enterprise (4.7) - with restricted output length
*, (20) usr41-server   no-gap inverse        "nder text-046
          hotspot quickinfo 'Go to this server'(827)
      .
    endif.
*   format color col_normal inverse.
    write:
      sy-vline         no-gap
    , usr41-logon_date no-gap color col_group "ntensified
    , sy-vline         no-gap
    , usr41-logon_time no-gap color col_group "ntensified
    , sy-vline         no-gap
    .
    hide:
      usr41-mandt
    , usr41-bname
    , usr41-terminal
    , usr41-termid
    , usr41-server
    .
    format color = cl_term intensified = intens inverse off.
  endselect.

  if sy-subrc = 0.
    write / sy-uline(u1).
    if f_pwdinfo = 'X'. put_pwdinfo. endif.
  else.
    put_pwdinfo.
  endif.

  cls ui2.
  call function 'TH_LONG_USR_INFO'
       exporting
         user      = sel_bname
       tables
         user_info = ui2
         .
  skip.
  format color = col_heading intensified = intens.

  data:
    hh(2)
  , mm         like hh
  , ss         like hh
  , time       like sy-uzeit
* , time       type t
  , utime      like time
  , delta      like time
  , udiff      like sy-uzeit
  , col_udiff  type i
  , cl_object  type i
  , cl_privsum type i
  .
* move sy-uzeit to time.
*-Synchronize the ABAP clock with the system time of the database server
  get time field time.
  write:
    (08) ' Time'(053) inverse no-gap
  ,  time inverse using edit mask t_mask no-gap
  .
  sort ui2 by time descending. read table ui2 index 1.
  if not ui2-time is initial.
    move ui2-time to utime.
    delta = time - utime.
    if delta >= '235000'. delta  = '000000'. endif.

    if delta > 0.
      if     delta between '000001' and '002959'.  " 1 sec .. 30 min
        col_waste = col_normal.
      elseif delta between '003000' and '005959'.  "30 min ..  1 hour
        col_waste = col_heading.
      elseif delta ge      '010000'.             "Greater than 1 hour
        col_waste = col_negative.
      endif.
      hh = delta(2). mm = delta+2(2). ss = delta+4(2).
      write (15) ' Wastetime'(047) inverse no-gap.
      perform write_time_part using hh '_hrs._'(048).
      perform write_time_part using mm '_min._'(049).
      perform write_time_part using ss '_sec._'(050).
    endif.
  endif.

  format color col_normal intensified off inverse.
*-Strip the icon '@32@' from the internal text 816 before output
  move text-816 to st_newmod. ln_newmod = strlen( st_newmod ) - 4.
*-Prevent dump
  if ln_newmod > 0.
    st_newmod = st_newmod+4(ln_newmod).
  endif.
  write:
    at 62 p_newmod as checkbox input off color col_normal hotspot
  ,      st_newmod inverse
  .
  if p_fail = 'X'.
    select single * from usr07 client specified
                         where mandt  = p_mandt
                           and bname  = sel_bname
                           and objct <> space
                           .
    if sy-subrc = 0.
      select single ttext into v_objt
                          from tobjt
                          where langu  = langu "sy-langu
                            and object = usr07-objct
                                .
      if sy-subrc <> 0.
        v_objt = '[ description in language & not found ]'(086).
        replace amp with langu into v_objt. condense v_objt.
      endif.
*-----Setup color for auth. object:
*       BLUE  - actual failure, auths. not granted yet
*       WHITE - these auths. already granted
*       RED   - failure from another client, can't be displayed here
      if p_mandt <> sy-mandt.
        cl_object = col_negative. inv = 1.
      else.
        perform simulate_auth_check.
        case sy-subrc.
          when 0.
            case fail_subrc.
              when 0.      cl_object = col_background. inv = 1.
              when others. cl_object = col_key.        inv = 1.
            endcase.
          when others.
            case fail_subrc.
              when 0.      cl_object = col_total.      inv = 0.
              when 24.     cl_object = col_group.      inv = 0.
              when others. cl_object = col_negative.   inv = 0.
            endcase.
        endcase.
      endif.

      write: at 99
        su53_icon as icon hotspot
          quickinfo 'Last Registered Auth. Failure'(817)
      , usr07-objct color = cl_object inverse = inv
          quickinfo  v_objt
      , wusr_icon as icon hotspot
          quickinfo 'Search in user master records'(111)
      , wagr_icon as icon hotspot
          quickinfo 'Search in roles (activity groups)'(112)
      , dele_icon as icon hotspot
          quickinfo 'Delete obsolete entry from USR07'(098)
      .
    endif.
    write at 122
      form_icon as icon hotspot
        quickinfo 'Request to change user rights'(113)
    .
    if f_histtab = 'X'.
      select count( * ) from (histtab) client specified
                        where mandt = p_mandt
                          and bname = sel_bname
                              .
      if sy-subrc = 0.
        write
          hist_icon as icon hotspot
            quickinfo 'View history of reg. failures'(777)
        .
      endif.
    endif.
  endif.

  format color col_normal inverse off.

  write / sy-uline(i2).
  format color = cl_tran_head intensified = intens.
  write:
  /  sy-vline                                    no-gap
  , (03) 'Cli'(201)                              no-gap
  ,  sy-vline                                    no-gap
* , (12) 'User'(202)                             no-gap
* ,  sy-vline                                    no-gap
  , (02) 'La'(057)                               no-gap
  ,  sy-vline                                    no-gap
  , (08) 'Time'(212)                             no-gap
  ,  sy-vline                                    no-gap
  ,  icon_layout_control       as icon                     " 3G
  ,  icon_execute_object       as icon                     " 15
  , (20) 'Transaction code'(058)                 no-gap
  ,  sy-vline                                    no-gap
  , (36) 'Transaction text'(059)                 no-gap
  ,  sy-vline                                    no-gap
  ,  icon_biw_monitor          as icon                     " 6P
* ,  icon_bw_exception_monitor as icon                     " MS
* ,  icon_exception            as icon                     " MV
  , (20) 'Terminal'(054)                         no-gap
  ,  sy-vline                                    no-gap
  , (04) 'Sess'(051)                             no-gap
  ,  sy-vline                                    no-gap
*-for SAP R/3 Release 4.6C
  , (01) 'M'(055)                                no-gap
*-for SAP R/3 Enterprise (4.7)
* , (03) 'Mod'(055)                              no-gap
  ,  sy-vline                                    no-gap
  , (08) 'Stoppage'(213)                         no-gap
  ,  sy-vline
  .
  if p_swst01 = 'X'.
*---Get trace state (ST01)
    perform get_trace_state.
    format color col_normal inverse.
    if     f_main_off = 'X'.
      st01_symb = sym_bold_x.
*     st01_icon = icon_incomplete.
    elseif f_auth_off = 'X'.
      st01_symb = sym_bold_minus.
*     st01_icon = icon_dummy.
    else.
      st01_symb = sym_check_mark.
*     st01_icon = icon_checked.
    endif.
    write st01_symb as symbol quickinfo sw_change.
*   write st01_icon as icon   quickinfo sw_change.
    format color col_normal inverse off.
  endif.

  write / sy-uline(i2).
  format color = cl_tran intensified = intens.
* sort ui2 descending by time. "may be also 'BY SESSION TIME'
  loop at ui2 assigning <fs3>.
*   if not fm_time_dif-exists is initial.
*     call function fm_time_dif-name
*          exporting
*            time1    = <fs3>-time
*            time2    = time
*          importing
*            diff     = udiff
*            col_diff = col_udiff
*            .
*   endif.
    data: t1 like sy-uzeit, t2 like t1.
    move: <fs3>-time to t1, time to t2.
    udiff = t2 - t1.
    if udiff >= '235000'. udiff = '000000'. endif.
*---Determine color:
*   if difference >= 3600 seconds then set colour to RED
    if     udiff ge 3600. col_udiff = col_negative.
    elseif udiff ge 1800. col_udiff = col_total.
                    else. col_udiff = col_normal.   endif.

    perform get_tcode_text using langu <fs3>-tcode changing ttext.

    write:
    /  sy-vline                              no-gap
    , (03) <fs3>-client                      no-gap "nder 'Cli'(201)
    ,  sy-vline                              no-gap
*   , (12) <fs3>-user                        no-gap "nder 'User'(202)
*   ,  sy-vline                              no-gap
    , (02) <fs3>-lang                        no-gap "nder text-057
    ,  sy-vline                              no-gap
    , (08) <fs3>-time using edit mask t_mask no-gap "nder text-212
    ,  sy-vline                              no-gap
    .
    if not <fs3>-tcode is initial.
      perform get_program_by_tcode using <fs3>-tcode
                                changing v_repid
                                         .
      concatenate 'View source'(814) v_repid
             into  q_source
                   separated by space
                   .
      write:
      abap_icon as icon hotspot              " 3G
        quickinfo q_source
    , tran_icon as icon hotspot              " 15
*       quickinfo 'Run transaction'(815)
    .
    endif.

    write:
*============================================================
      (20) <fs3>-tcode under 'Transaction code'(058) no-gap
*      at 24(20)
*          <fs3>-tcode                  no-gap "nder text-058
*============================================================
    ,  sy-vline                         no-gap
    , (36) ttext                        no-gap "nder text-059
    ,  sy-vline                         no-gap
    ,  moni_icon as icon hotspot              " 6P
*        quickinfo 'Connect to this terminal via VNC'(669)
    , (20) <fs3>-terminal               no-gap "nder text-054
    ,  sy-vline                         no-gap
    , (04) <fs3>-session                no-gap "nder text-051
    ,  sy-vline                         no-gap
*-for SAP R/3 Release 4.6C
    , (01) <fs3>-mode                   no-gap "nder text-055
*-for SAP R/3 Enterprise (4.7)
*   , (03) <fs3>-mode                   no-gap "nder text-055
    ,  sy-vline                         no-gap
    .
*   if not fm_time_dif-exists is initial.
      write:
        udiff                           no-gap "nder text-213
        color = col_udiff
      , sy-vline
      .
*   else.
*     write:
*      (08) 'NotAvail'(913)             no-gap "nder text-213
*       color = col_normal inverse
*     , sy-vline
*     .
*   endif.

*---Import data before hiding cause we can't hide field-symbols directly
    ui2-terminal = <fs3>-terminal.
    ui2-tcode    = <fs3>-tcode.
    ui2-lang     = <fs3>-lang.
    hide:
      ui2-lang
    , ui2-tcode
    , ttext
    , ui2-terminal
    .
  endloop.

  if not ui2[] is initial.
    write / sy-uline(i2).
    if p_detail = 'X'.
      memd_symb = sym_right_triangle.
      perform build_mem_list.
      delete usr_btabl where bname <> sel_bname.
      format color col_heading inverse.
      write:
       /3 memd_symb as symbol hotspot quickinfo 'Hide'(960)
      , 5(10) 'PAGE mem.'(555) color col_normal inverse off
      ,  (10) 'ROLL mem.'(556) color col_normal inverse off
      ,  (10) 'Mem.(sum)'(558) color col_normal inverse off
      ,  (10) 'PRIV mem.'(559) color col_normal inverse off
      .
      refresh it_total.
      loop at usr_btabl into wa.
        write:
        / wa-page    under 'PAGE mem.'(555)
        , wa-roll    under 'ROLL mem.'(556)
        , wa-memsum  under 'Mem.(sum)'(558)
        , wa-privsum under 'PRIV mem.'(559)
        .
        move-corresponding wa to wa1.
        collect wa1 into it_total.
      endloop.
      read table it_total index 1.
      write:
        /5(43) sy-uline
      , / it_total-page   under 'PAGE mem.'(555)
      ,   it_total-roll   under 'ROLL mem.'(556)
      ,   it_total-memsum under 'Mem.(sum)'(558)
            color col_total inverse off
      .
      if it_total-privsum is initial.
        cl_privsum = col_total.
      else.
        cl_privsum = col_negative.
      endif.
      write
        it_total-privsum under 'PRIV mem.'(559)
          color = cl_privsum inverse off
      .
    else.
      memd_symb = sym_down_triangle.
      format color col_heading inverse.
      write:
       /3  memd_symb as symbol hotspot quickinfo 'Show'(961)
      , 5 'Show memory consumpted by this user'(962)
      .
    endif.
    free ui2.
  endif.

  if f_multi = 'X'. perform show_extra_servers. endif.
  act_ind = sy-lsind + 1.
  perform list_return using act_ind.   "Return to previous position
  if f_visible = '1'.
    perform build_document using sel_bname.
  endif.
endform. "SHOW_LONG_USR_INFO
*-----------------------------------------------------------------------
data w_ulist like uinfos occurs 10 with header line.

form show_extra_servers.
  data:
    s_tcode  like tstc-tcode
  , len_tcd  type i
  , f_single
  .
  format color col_normal inverse.
  write:
  /, /2 'Preview for servers which name differs with my'(935)
  ,      myname color col_heading inverse
  ,  /
  .
  call function 'TH_SYSTEMWIDE_USER_LIST'
       tables
         list           = w_ulist
       exceptions
         argument_error = 1
         send_error     = 2
         others         = 3
         .
  if sy-subrc <> 0.
    write:
    /2 '@3U@'                 "3U, 02, 8N, 8O, AG, DR, MG
    ,  'Cannot get this information due to error #'(936)
    ,   sy-subrc
    .
    exit.
  endif.

  delete w_ulist where bname <> sel_bname.
  delete w_ulist where apserver = myname.
  sort   w_ulist by apserver ascending zeit descending.

  loop at w_ulist.
    at new apserver.
      format color col_heading inverse.
      write:
         /2 '@MA@'               "MA, 6K, KR, BZ, P8, v_icon2
      ,   6 'Extra server:'(932)
      ,      w_ulist-apserver
      , 106 'Int'(933)
      , 111 'Ext'(934)
      .
      hide w_ulist-apserver.
      write / sy-uline(i2).
    endat.

    format color col_normal inverse off.

    clear: ttext, f_single.
    if w_ulist-tcode is initial.
      f_single = 'X'.
    else.
      move w_ulist-tcode to s_tcode. condense s_tcode.
      len_tcd = strlen( s_tcode ).
      if len_tcd > 3.
        concatenate s_tcode '%' into s_tcode.
        condense s_tcode.
      endif.
      select count( * ) from tstc where tcode like s_tcode.
      if sy-subrc = 0.
        case sy-dbcnt.
          when 1.
            f_single = 'X'.
            select single tcode into w_ulist-tcode
                                from tstc
                                where tcode like s_tcode
                                      .
            modify w_ulist.
            perform get_tcode_text using langu w_ulist-tcode
                                changing ttext
                                         .
          when others.
            ttext = '[not enough data to get description]'(937).
        endcase.
      else.
        ttext = '[    unknown transaction code      ]'(938).
      endif.
    endif.

    write:
       /1  sy-vline
    ,   2  w_ulist-mandt
    ,   9  w_ulist-zeit
    ,  24  w_ulist-tcode
    .
    if f_single is initial. write 28 dot3. endif.
    write:
       45  ttext
    ,  85  w_ulist-term
    , 106  w_ulist-intmodi
    , 111  w_ulist-extmodi
    , 121  sy-vline no-gap
    .
    hide w_ulist-term.
    at end of apserver. write / sy-uline(i2). endat.
  endloop.

  free w_ulist.
endform. "SHOW_EXTRA_SERVERS
*-----------------------------------------------------------------------
data idx like sy-tabix.

form another_user using shift type i skip_flg.
  data err_flg.

  clear err_flg.
  read table it transporting no fields with key bname = sel_bname.
  if sy-subrc <> 0.
    app_log_z2_1 '030' text-376.
    message s030 with 'The user not in selection. Sorry...'(376).
    exit.
  endif.

  if not skip_flg is initial. perform get_activity. endif.
  do.
    idx = sy-tabix + shift.
    read table it index idx transporting bname online.
    if sy-subrc <> 0. move 'X' to err_flg.
      app_log_z2_0 '016'.
*----'No way in this direction'
      message s016.
      exit.
    endif.
    if skip_flg is initial.
      exit.
    else.
      if it-online is initial. continue. else. exit. endif.
    endif.
  enddo.

  if err_flg is initial.
    sel_bname = it-bname. set_titlebar_001.
    perform smart_show_long_usr_info.
  endif.
endform. "ANOTHER_USER
*-----------------------------------------------------------------------
form uline_sess using value(f_corner) value(f_middle).
  constants:
*-for SAP R/3 Release 4.6C
    u1    like sy-staco value 184   "Underline width (when details ON)
  , u2    like u1       value 119   "Underline width (when details OFF)
*-for SAP R/3 Enterprise (4.7)
*   u1    like sy-staco value 204   "Underline width (when details ON)
* , u2    like u1       value 139   "Underline width (when details OFF)
  .
  data:
    u     like u1
  , line1 like line_left_middle_corner
  , line2 like line1
  .
  if p_detail = 'X'. u = u1. else. u = u2. endif.

  if f_corner = 'X'.
    subtract 2 from u.
    if f_middle = 'X'.
      line1 = line_left_middle_corner.
      line2 = line_right_middle_corner.
    else.
      line1 = line_bottom_left_corner.
      line2 = line_bottom_right_corner.
    endif.
    write:
    / line1 as line no-gap
    , sy-uline(u)   no-gap
    , line2 as line no-gap
    .
  else.
    write / sy-uline(u).
  endif.
endform. "ULINE_SESS
*-----------------------------------------------------------------------
form get_cursor_field.
  if sy-curow gt head_bo_s and        "If relative line > HEAD_RO_S and
     sy-lilli le last_ln_s.           "  absolute line inside of list
    clear fld. get cursor field fld.
*---for prevent dump when SY-VLINE selected
    if fld = 'SY-VLINE'. clear fld. exit. endif.
*   if fld = 'SY-VLINE'.            exit. endif.
*---get field name of internal table
    split fld at '-' into tab fld.
  else. clear fld. endif.
endform. "GET_CURSOR_FIELD
*-----------------------------------------------------------------------
form sort_it41s.
* data direction(14).
  if     fld is initial.
*--'Position cursor on a table field'
*   message id 'GH' type 'W' number '705'.
*--'Position cursor on a table field'
*   message id 'PS' type 'W' number '137'.
*--'Position the cursor on a table field'
*   message id 'TD' type 'W' number '303'.
**  exit.
    select_valid_field.
* elseif fld eq 'SY-VLINE'.
**-'Take the choice'
**  message id '14' type 'W' number '101'.
**-'Position the cursor on a list line.'
*   message id '00' type 'W' number '301'.
**  exit.
  endif.
  if sort_flg = 'X'.
    sort it41s stable by (fld)  ascending.  " STABLE sorting!
*   move  'ascending by'(214) to direction.
  else.
    sort it41s stable by (fld) descending.  " STABLE sorting!
*   move 'descending by'(215) to direction.
  endif.
* app_log_z2_3 '017' direction text-216 fld.
* message s017 with direction 'field'(216) fld.
endform. "SORT_IT41S
*-----------------------------------------------------------------------
form get_thusrinfo.
  cls it_th.
  call function 'THUSRINFO'
       tables
         usr_tabl = it_th
         .
  sort it_th by zeit descending.
endform. "GET_THUSRINFO
*-----------------------------------------------------------------------
form count_extra.
  if expert is initial or f_th_all is initial.
    delete it_th where type = 4 "GUI
                   and stat = 2 "Connected
                       .
  endif.
  describe table it_th lines extra_cnt.
  move extra_cnt to st_extra. condense st_extra.

  clear: rfc_cnt, others_cnt, zombie_cnt.
  loop at it_th.
*---Connection type
    case it_th-type.
*     when   4.
      when  32.    add 1 to rfc_cnt.
*     when 202.    add 1 to others_cnt.
      when others. add 1 to others_cnt.
    endcase.
*---Connection status
    case it_th-stat.
*     when   2.
      when   4.    add 1 to zombie_cnt.
*     when   6.
*     when others.
    endcase.
  endloop.
endform. "COUNT_EXTRA
*-----------------------------------------------------------------------
form get_activity_s.
* perform issue_select.
  clear f_sele_s.

  if p_detail = 'X'. perform build_mem_list. endif.

  perform get_thusrinfo.
  cls it41s. clear sum_act_s.

  select * from usr41 client specified into it41s.
*---If user has no authority to read system traces
*   then remove IP-Address part from TERMINAL
    if auth_st0r is initial or p_no_ip = 'X'.
      split it41s-terminal at '-' into it41s-terminal it41s-terminal.
    endif.

*---First, read an internal table (faster!)
    read table it with key mandt = it41s-mandt bname = it41s-bname.
*---if entry not found, read data from DB
    if sy-subrc <> 0.
      perform get_user_name
                      using it41s-mandt      it41s-bname
                   changing it41s-name_first it41s-name_last
                            .
    else. r_names it41s-name_first it41s-name_last. endif.

*---Redundant block BEGIN
    clear f_exception.
    if it41s-server = myname.
      perform get_user_time_th. " <--This may raise F_EXCEPTION !!!
    else.
      clear: it41s-time, it41s-diff. move '?' to it41s-diff.
    endif.
*---Redundant block END

    if p_detail = 'X'.
      if it41s-server = myname.
        read table usr_btabl
             with key mandt = it41s-mandt
                      bname = it41s-bname
*                     tcode = it41s-tcode "NOT TESTED YET
                      tid   = it41s-termid
                      .
        if sy-subrc = 0. move-corresponding usr_btabl to it41s. endif.
      else.
        clear: it41s-tcode
             , it41s-key
             , it41s-page
             , it41s-roll
             , it41s-tid
             , it41s-memsum
             , it41s-privsum
             .
      endif.
    endif.
    if f_exception is initial. append it41s. endif.
  endselect.

  if p_extra = 'X'.
    perform count_extra.
    perform fill_it_extra.
  else.
    free it_th.
  endif.

  if p_match = 'X'.
    perform sort_it41s.
    loop at it41s.
      read table it with key bname = it41s-bname
                 transporting no fields
                 .
      if sy-subrc <> 0. delete it41s. endif.
    endloop.
    if p_wide is initial.
      delete it41s where mandt <> mandt_f.
    endif.
  endif.

* delete adjacent duplicates from it41s.
  describe table it41s lines sum_act_s.
  move sum_act_s to str_act_s. condense str_act_s.
  if p_match = 'X'. ind_match = '*'. else. clear ind_match. endif.
  set titlebar 'SES' with sy-sysid str_act_s ind_match.
  perform sort_it41s.
endform. "GET_ACTIVITY_S
*-----------------------------------------------------------------------
form get_user_time_th.
  data:
    t    like sy-uzeit
  , ut   like t
  , diff like t
  .
* clear f_exception. "<-- Moved to upper level
  read table it_th with key tid   = it41s-termid
                            mandt = it41s-mandt
                            bname = it41s-bname
                            type  = 4 "GUI
                            .
  if sy-subrc <> 0.
*   read table it_th with key mandt = it41s-mandt
*                             bname = it41s-bname
*                             type  = 4 "GUI
*                             .
*   if sy-subrc <> 0.
**    clear: it41s-time, it41s-diff.
*     clear  it41s-time. move '?' to it41s-diff.
*     exit.
*   endif.
    clear it41s-time. move '?' to it41s-diff.
    f_exception = 'X'.
    exit.
  endif.

* move sy-uzeit to t.
*-Synchronize the ABAP clock with the system time of the database server
  get time field t.
  if not it_th-zeit is initial.
    move:
*     it_th-tcode to it41s-tcode                  "NOT TESTED YET
      it_th-zeit  to it41s-time
    , it_th-zeit  to ut
    .
    diff = t - ut. if diff >= '235000'. diff = '000000'. endif.
    move diff to it41s-diff.
  endif.
endform. "GET_USER_TIME_TH
*-----------------------------------------------------------------------
define uline_extra.
  write /(131) sy-uline.
end-of-definition. "ULINE_EXTRA
*-----------------------------------------------------------------------
define header_s_gui.
  if p_match = 'X'. cl_s_gui = col_group.
              else. cl_s_gui = col_heading. endif.
  format color = cl_s_gui intensified.

  perform uline_sess using ' ' ' '.
  write:
  /  sy-vline                      no-gap
  ,  f_sele_s as checkbox input off hotspot
  , (03) 'Cli'(201)
  , (12) 'User'(202)
  .
  if p_scroll = 'X'.
    set left scroll-boundary.       "Nale down three columns here
  endif.

  write:
    (15) 'Last name'(003)
  , (24) 'First name'(004)
  , (27) 'Terminal'(203)
  .
  if waste_flg is initial.
    write (08) 'Time'(212)         no-gap.
  else.
    write (08) 'Stoppage'(213)     no-gap.
  endif.
* write   (10) 'TERMID'(204).
  write:
       sy-vline                    no-gap
*-for SAP Release 4.6C
  ,   (20) 'Server'(046)           no-gap
*-for SAP R/3 Enterprise (4.7)
* ,   (40) 'Server'(046)           no-gap
  ,    sy-vline                    no-gap
  .
  ps_sm51 = sy-colno - 7.

  if p_detail = 'X'.
    write:
      (20) 'Transaction code'(058) no-gap
    ,  sy-vline                    no-gap
*   , (10) 'KEY'(554)              no-gap
*   ,  sy-vline                    no-gap
    , (10) 'PAGE mem.'(555)        no-gap
    ,  sy-vline                    no-gap
    , (10) 'ROLL mem.'(556)        no-gap
    ,  sy-vline                    no-gap
*   , (10) 'TID'(557)              no-gap
*   ,  sy-vline                    no-gap
    , (10) 'Mem.(sum)'(558)        no-gap
    ,  sy-vline                    no-gap
    , (10) 'PRIV mem.'(559)        no-gap
    ,  sy-vline                    no-gap
    .
  endif.
  perform put_aref.
  perform put_aref_updown.

  write: at ps_sm51
    sm51_icon as icon
      color = cl_s_gui intensified on
      hotspot quickinfo 'SM51'(221)
*     hotspot quickinfo 'SM51 - List of SAP Systems'(221)
 ,  sm66_icon as icon
      color = cl_s_gui intensified on
      hotspot quickinfo 'SM66'(222)
*     hotspot quickinfo 'SM66 - Systemwide Work Process Overview'(222)
  .
  perform uline_sess using 'X' 'X'.
  perform put_sort_indicator_s.
end-of-definition. "HEADER_S_GUI
*-----------------------------------------------------------------------
define header_s_extra.
  uline_extra.
  format color = cl_extra inverse off intensified on.

  write:
  /  sy-vline                    no-gap
  ,  space                       no-gap
  ,  sy-vline                    no-gap
  , (03) 'Cli'(201)              no-gap
  ,  sy-vline                    no-gap
  , (12) 'User'(202)             no-gap
  ,  sy-vline                    no-gap
  .
  if p_scroll = 'X'.
    set left scroll-boundary.     "Nale down three columns here
  endif.

  write:
    (20) 'Transaction code'(058) no-gap
  ,  sy-vline                    no-gap
  , (10) 'Term.ID'(045)          no-gap
* , (10) text-045                no-gap
  ,  sy-vline                    no-gap
  , (15) 'IP address'(797)       no-gap
  ,  sy-vline                    no-gap
  , (20) 'Terminal'(054)         no-gap
  ,  sy-vline                    no-gap
  , (08) 'Dia.Time'(852)         no-gap
  ,  sy-vline                    no-gap
  , (04) 'Type'(841)             no-gap
  ,  sy-vline                    no-gap
  , (06) 'C.Type'(850)           no-gap
  ,  sy-vline                    no-gap
  , (09) 'Status'(851)           no-gap
  ,  sy-vline                    no-gap
  , (10) 'GUI vers.'(849)        no-gap
  ,  sy-vline                    no-gap
  .
  uline_extra.
  format color = cl_extra inverse off intensified off.
end-of-definition. "HEADER_S_EXTRA
*-----------------------------------------------------------------------
form do_header_s.
* check sy-pfkey = 'SESS'.

* if sy-cpage > 1.
  if sy-pagno > 1.
*---Header for Extra Sessions
    header_s_extra.
  else.
*---Header for GUI sessions
    header_s_gui.
  endif.
endform. "DO_HEADER_S
*-----------------------------------------------------------------------
data:
  col_mandt_s type i
, col_sess    type i
.
form print_table_s.
  data:
    ls_idx    like sy-lsind value 1        "List index
  , i         type     i    value 0
  , col_privs type     i
  .
  perform init_block_s.
  if sy-lsind > ls_idx. perform back_if_detail. endif.

  format color col_normal.

  loop at it41s. "assigning <fs2>. <-does not work with GET CURSOR FIELD
    i = ( i + 1 ) mod 2.
    format intensified = i.
    mac_determine_colors_s.
    write:
    /      sy-vline no-gap
    ,      it41s-mark as checkbox input off hotspot
             color = col_sess
    ,      it41s-mandt      "nder 'Cli'(201)  " unrestricted = 03
             color = col_mandt_s
    ,      it41s-bname      "nder 'User'(202) " unrestricted = 12
             color = col_sess
    , (15) it41s-name_last  "nder text-003    " unrestricted = 40
             color = col_sess
    , (24) it41s-name_first "nder text-004    " unrestricted = 40
             color = col_sess
    , (27) it41s-terminal   "nder text-203    " unrestricted = 36
    .
*---Copy desired information to global variable before HIDE,
*   cause we can't hide field-symbols (system will generate a dump!)
*   move:
*     <fs2>-mandt to it41s-mandt
*   , <fs2>-bname to it41s-bname
*   .
    hide:
      it41s-mandt
    , it41s-bname
    , it41s-termid
    , it41s-server
    , it41s-mark
    .
    if it41s-server = myname.
      if waste_flg is initial.
        write  it41s-time using edit mask t_mask no-gap. "nder text-212.
      else.
*-------if wastetime >= 3600 seconds then set colour to RED
        if     it41s-diff ge 3600. col_diff = col_negative.
        elseif it41s-diff ge 1800. col_diff = col_total.
                             else. col_diff = col_normal.   endif.
        write  it41s-diff color = col_diff
                          using edit mask t_mask no-gap. "nder text-213.
      endif.
*     write    it41s-termid        under text-004.  " unrestricted = 10
      write:   sy-vline     no-gap
*-----for SAP R/3 Release 4.6C
      ,        it41s-server no-gap "nder text-046
*-----for SAP R/3 Enterprise (4.7) - with restricted output length
*     ,   (20) it41s-server no-gap "nder text-046
      ,        sy-vline     no-gap
      .
    else.
      if waste_flg is initial.
        write  it41s-time using edit mask t_mask2 no-gap inverse
*                         under text-212
                          .
      else.
        write  it41s-diff using edit mask t_mask2 no-gap inverse
*                         under text-213
                          .
      endif.
*     write    it41s-termid        under text-004.  " unrestricted = 10
      write:   sy-vline     no-gap
*-----for SAP R/3 Release 4.6C
      ,        it41s-server no-gap inverse "nder text-046
*-----for SAP R/3 Enterprise (4.7) - with restricted output length
*     ,   (20) it41s-server no-gap inverse "nder text-046
      ,        sy-vline     no-gap
      .
    endif.
    hide it41s-server.
    if p_detail = 'X'.
      if it41s-server = myname.
*       My server, normal output
        write:
          it41s-tcode   no-gap
        , sy-vline      no-gap
*       , it41s-key     no-gap
*       , sy-vline      no-gap
        , it41s-page    no-gap
        , sy-vline      no-gap
        , it41s-roll    no-gap
        , sy-vline      no-gap
*       , it41s-tid     no-gap
*       , sy-vline      no-gap
        , it41s-memsum  no-gap
        , sy-vline      no-gap
        .
        if it41s-privsum is initial.
          col_privs = col_normal.
        else.
          col_privs = col_negative.
        endif.
        write it41s-privsum no-gap color = col_privs.
      else.
*       Alien server, inverse output
        write:
          it41s-tcode   no-gap inverse
        , sy-vline      no-gap
*       , it41s-key     no-gap inverse
*       , sy-vline      no-gap
        , it41s-page    no-gap inverse
        , sy-vline      no-gap
        , it41s-roll    no-gap inverse
        , sy-vline      no-gap
*       , it41s-tid     no-gap inverse
*       , sy-vline      no-gap
        , it41s-memsum  no-gap inverse
        , sy-vline      no-gap
        , it41s-privsum no-gap inverse
        .
      endif.

      write sy-vline no-gap.
    endif.
  endloop.
  move sy-linno to last_ln_s.    "Remember number of last line in list

  perform uline_sess using 'X' ' '.

  format color col_key inverse.
*-Prevent horizontal scrolling for the following line
  new-line no-scrolling.
  if p_match = 'X'.
    write:
    /2 xcel_icon as icon hotspot quickinfo text-341 "Export to Excel
*   , 'Export to Excel'(341)
    , (2) space
    ,  note_symb as symbol
    , 'List has been restricted according to sel. screen criteria'(083)
    .
*---Prevent horizontal scrolling for the following line
    new-line no-scrolling.
    if p_wide = 'X'.
      wide_icon = icon_absence.
      write:
      /  wide_icon as icon hotspot under note_symb
      , 'Client restriction is OFF, shown entries for all clients'(088)
      .
    else.
      wide_icon = icon_presence.
      write:
      /  wide_icon as icon hotspot under note_symb
      , 'Client restriction is ON, shown entries for client'(089)
      ,  mandt_f input color col_total inverse off intensified no-gap
      ,  clis_icon as icon hotspot
      .
    endif.
    hide mandt_f.
  else.
    write:
    /2 xcel_icon as icon hotspot quickinfo text-341 "Export to Excel
*   , 'Export to Excel'(341)
    , (2) space
    ,  note_symb as symbol
    , 'List has not been restricted'(978)
    .
  endif.

  perform put_extra.
  perform list_return using 2.   "Return to previous position
endform. "PRINT_TABLE_S
*-----------------------------------------------------------------------
form put_extra.
  constants
    gui_standard like it_extra-guiversion value '620'
  .
  data:
    cl_vers      type i
  , q_extra      like rsmpe_txt-quickinfo
  .
  define uline_pre_extra.
*---Prevent horizontal scrolling for the following line
    new-line no-scrolling.
    write /4(25) sy-uline.
  end-of-definition. "ULINE_PRE_EXTRA

  if p_extra = 'X' and not it_th[] is initial.
    skip.
    format color col_heading inverse.
*---Prevent horizontal scrolling for the following line
    new-line no-scrolling.
    if f_extr is initial.
      extr_symb =  sym_large_square.
      q_extra   = 'Show'(961).
    else.
      extr_symb =  sym_checkbox.
      q_extra   = 'Hide'(960).
    endif.

    write:
    2  extr_symb as symbol hotspot quickinfo q_extra
    , 'RFC connections/others'(840) no-gap
    , ':'
    ,  st_extra
    .
    if not f_extr is initial.
      write:
         frup_symb as symbol hotspot quickinfo 'Previous'(156)
      , 'fragment'(155)
      ,  frdn_symb as symbol hotspot quickinfo 'Next'(157)
      .
    endif.

*   if not expert is initial.
*     write
*       at 60 f_th_all
*       as checkbox input off hotspot
*       quickinfo 'Internal use: Show All Entries/Extra only'(170)
*     .
*   endif.

*---Remember line number
*   move sy-lilli to extr_ln.
    move sy-linno to extr_ln.

*---Write RFC counter (if it isn't zero and differs with total)
    if rfc_cnt > 0 and rfc_cnt < extra_cnt.
      uline_pre_extra.
*-----Prevent horizontal scrolling for the following line
      new-line no-scrolling.
      write:
      /4 '@BW@RFC connections:'(839)
      ,   rfc_cnt    left-justified
      .
    endif.

*---Write Other counter (if non-zero)
    if others_cnt <> 0.
*-----Prevent horizontal scrolling for the following line
      new-line no-scrolling.
      write:
      /4 '@6L@Other  sessions:'(837)
      ,   others_cnt left-justified
      .
    endif.

*---Write Zombie counter (if non-zero)
    if zombie_cnt <> 0.
      uline_pre_extra.
*-----Prevent horizontal scrolling for the following line
      new-line no-scrolling.
      write:
      /4 '@CR@Zombie sessions:'(838)
      ,   zombie_cnt left-justified
      .
    endif.

*---Show RFC connections, lost GUI sessions, plugins...
    if not f_extr is initial.
      new-page
        no-title
        no-heading
      .
      format color = cl_extra inverse off intensified off.

      loop at it_extra.
        if it_extra-rfc_type = 'E'.
          erfc_symb = sym_filled_circle.
        else.
          erfc_symb = sym_circle.
        endif.

        if not it_extra-guiversion is initial
           and it_extra-guiversion < gui_standard  "#EC PORTABLE
               .
          cl_vers = col_total.
        else.
          cl_vers = cl_extra.
        endif.

        write:
        / sy-vline             no-gap
        , erfc_symb as symbol  no-gap "Is it external RFC?
        , sy-vline             no-gap
        , it_extra-mandt       no-gap "Client
        , sy-vline             no-gap
        , it_extra-bname       no-gap "User
        , sy-vline             no-gap
        , it_extra-tcode       no-gap "Transaction code
        , sy-vline             no-gap
        , it_extra-tid         no-gap "Terminal ID
        , sy-vline             no-gap
        , it_extra-ip_addr     no-gap "IP address
        , sy-vline             no-gap
        , it_extra-term        no-gap "Terminal
        , sy-vline             no-gap
        , it_extra-zeit        no-gap using edit mask t_mask
        , sy-vline             no-gap
        , it_extra-iconid      no-gap as icon "Icon
            quickinfo it_extra-iconid_info
        , sy-vline             no-gap
        , it_extra-type_txt    no-gap "Connection type   (text)
        , sy-vline             no-gap
        , it_extra-stat_txt    no-gap "Connection status (text)
            color = it_extra-stat_col
        , sy-vline             no-gap
        , it_extra-guiversion  no-gap "GUI version
            color = cl_vers
        , sy-vline             no-gap
        .
        hide:
          it_extra-tid
        , it_extra-mandt
        , it_extra-bname
        , it_extra-tcode
        , it_extra-term
        , it_extra-zeit
        , it_extra-hostadr
        .
      endloop.
      uline_extra.
      format color col_heading inverse.
      new-line no-scrolling.
      write:
      2  jump_symb as symbol hotspot quickinfo 'Go'(141)
      , 'Top of extra sessions'(137)
      ,  frup_symb as symbol hotspot quickinfo 'Previous'(156)
           under frup_symb
      , 'fragment'(155)
      ,  frdn_symb as symbol hotspot quickinfo 'Next'(157)
           under frdn_symb
      .
    endif.
  endif.
endform. "PUT_EXTRA
*-----------------------------------------------------------------------
form sort_list_s.
  data prev_fld like fld.
  prev_fld = fld.

  perform get_cursor_field.
  if fld is initial. fld = prev_fld. endif.

  perform sort_it41s.
  perform print_table_s.
endform. "SORT_LIST_S
*-----------------------------------------------------------------------
form show_active_sessions.
  if auth_st0r is initial.
    set pf-status 'SESS' excluding 'NOIP'.
  else.
    set pf-status 'SESS'.
  endif.
  perform refresh_list_s.
endform. "SHOW_ACTIVE_SESSIONS
*-----------------------------------------------------------------------
form cmd_refresh_list_s.
  perform call_rfc_ping_wait.
  perform refresh_list_s.
endform. "CMD_REFRESH_LIST_S
*-----------------------------------------------------------------------
form refresh_list_s.
  perform get_activity_s.
  perform print_table_s.
endform. "REFRESH_LIST_S
*-----------------------------------------------------------------------
form warning_on_user_logoff using user like sy-uname
                                  mand like sy-mandt
                                  .
*-----------------'in client'
  concatenate user text-041 mand '?' into pop_txt separated by space.
  confirm_step 'N'
               'Kill all sessions of the user'(305)
                pop_txt
               'Kick the user out'(306)
                .
endform. "WARNING_ON_USER_LOGOFF
*-----------------------------------------------------------------------
form kick_out_user.
  data syslog_msg(64).

  check_padm.

  get_and_check_sel_bname.
  if ( mandt_s = sy-mandt ) and ( sel_bname = sy-uname ).
    app_log_z2_0 '028'.
*--'If you want to delete your own sessions use transaction SM04'
    message w028.
*   exit.
  endif.

  perform warning_on_user_logoff using sel_bname mandt_s.
  if ans <> 'J'. exit. endif.

  call function 'TH_DELETE_USER'
       exporting
         user            = sel_bname
         client          = mandt_s
       exceptions
         authority_error = 1
         others          = 2
         .
  case sy-subrc.
    when 0.
*----------------Write Entry to System Log (see SM21, SE92)
                 concatenate mandt_s sel_bname
                            'disconn. by:'(700) sy-uname
                        into syslog_msg
                             separated by space
                             .
                 call 'C_WRITE_SYSLOG_ENTRY'
                   id 'TYP'  field 'm'
                   id 'KEY'  field 'US8'
                   id 'DATA' field  syslog_msg
                   .
*                set user-command 'REFR'.
*                perform show_active_sessions.
                 perform simulate_sapgui_update.

    when 1.
*---------------'Access denied: missing authorization &'
                 app_log_z2_0 '006'.
                 message w006 with space.

    when others.
*---------------'Can not logoff the user &1 in client &2'
                 app_log_z2_2 '027' sel_bname mandt_s.
                 message w027 with sel_bname mandt_s.
  endcase.
endform. "KICK_OUT_USER
*-----------------------------------------------------------------------
form check_program_existence using value(v_repid).
*-Warning: V_SUBC used here is a global variable
  select single name subc from trdir
                          into (v_repid, v_subc)
                          where name = v_repid
                                .
endform. "CHECK_PROGRAM_EXISTENCE
*-----------------------------------------------------------------------
form show_object.
  data v_show_obj like sy-repid value 'RSUSR040'.

*-Check program existence and type
  is_executable v_show_obj.

  perform issue_run_message using v_show_obj 'X'.
  submit (v_show_obj) with objct = usr07-objct and return.
  perform simulate_sapgui_update.
endform. "SHOW_OBJECT
*-----------------------------------------------------------------------
tables:
  dfies
, tobj
.
data:
  begin of it_af occurs 10
*   objct     like tobj-objct
,   field     like tobj-fiel0
,   value     like ust12-von
, end   of it_af

* List of the fields from current authorization object
, begin of intfield occurs 10
,   fieldname like tobj-fiel0
,   ftext     like tobjt-ttext
,   lng       like dfies-outputlen
, end   of intfield

, wa_usr07    like usr07
, vallng      like sy-fdpos value 40 "Value length (See MS01CTCO)
.
form load_intfield using object.
*-Original source see in include SR070F10 (or MS01CW31)
* of the report RSUSR070
  data:
    sfield like tobj-fiel0
  , rc     type i value 0
  .
  clear: tobj, intfield, intfield[].
  select single * from tobj
                  where objct = object
                        .
  do 10 times varying sfield from tobj-fiel1 next tobj-fiel2.
    if sfield <> space.
      intfield-fieldname = sfield.
      call function 'AUTH_FIELD_GET_INFO'
           exporting
             fieldname = sfield
           importing
             datel     = dfies-rollname
             lng       = dfies-outputlen
             rc        = rc
             text      = dfies-fieldtext
             inttype   = dfies-inttype
             .
      if rc is initial.
        if dfies-fieldtext <> space.
          intfield-ftext = dfies-fieldtext.
        else.
          intfield-ftext = sfield.
        endif.
        intfield-lng   = dfies-outputlen.
        if intfield-lng > vallng.
          intfield-lng = vallng.
        endif.
      else.
        intfield-ftext = sfield.
        intfield-lng = vallng.
      endif.
      append intfield.
    endif.
  enddo.
* Note 823915: order to display - by table TOBJ (like in SU21)
*-For SAP R/3 4.6C:
  if sy-saprl = '46C'.
    sort intfield by ftext fieldname.
  endif.
endform. "LOAD_INTFIELD
*-----------------------------------------------------------------------
define app_af.
  it_af-field = &1.
  it_af-value = &2.
  append it_af.
end-of-definition. "APP_AF
*-----------------------------------------------------------------------
define read_intfield.
  read table intfield index &1.
  if sy-subrc = 0.
    read table it_af with key field = intfield-fieldname.
    if sy-subrc = 0.
      &2 = it_af-value.
    else. clear &2. endif.
  else. clear &2. endif.
end-of-definition. "READ_INTFIELD
*-----------------------------------------------------------------------
form prepare_auth_fields.
  move-corresponding usr07 to wa_usr07.
  perform load_intfield using wa_usr07-objct.

  cls it_af.
  app_af wa_usr07-fiel0 wa_usr07-val01.
  app_af wa_usr07-fiel1 wa_usr07-val02.
  app_af wa_usr07-fiel2 wa_usr07-val03.
  app_af wa_usr07-fiel3 wa_usr07-val04.
  app_af wa_usr07-fiel4 wa_usr07-val05.
  app_af wa_usr07-fiel5 wa_usr07-val06.
  app_af wa_usr07-fiel6 wa_usr07-val07.
  app_af wa_usr07-fiel7 wa_usr07-val08.
  app_af wa_usr07-fiel8 wa_usr07-val09.
  app_af wa_usr07-fiel9 wa_usr07-val10.

  read_intfield  1 wa_usr07-val01.
  read_intfield  2 wa_usr07-val02.
  read_intfield  3 wa_usr07-val03.
  read_intfield  4 wa_usr07-val04.
  read_intfield  5 wa_usr07-val05.
  read_intfield  6 wa_usr07-val06.
  read_intfield  7 wa_usr07-val07.
  read_intfield  8 wa_usr07-val08.
  read_intfield  9 wa_usr07-val09.
  read_intfield 10 wa_usr07-val10.

  free it_af.
endform. "PREPARE_AUTH_FIELDS
*-----------------------------------------------------------------------
form where_used using v_suim_rep like sy-repid value(v_selset).
  if p_mandt <> sy-mandt.
    app_log_z2_1 '092' p_mandt.
*--'The program you've try to call cannot work with data from client &.'
    message i092 with p_mandt.
  endif.

  perform prepare_auth_fields.
*-Check program existence and type
  is_executable v_suim_rep.
*-Progress indicator may be omitted when submitting VIA SELECTION-SCREEN
  perform issue_run_message using v_suim_rep 'X'.
  submit (v_suim_rep)
   using selection-set v_selset
*   with objct  = usr07-objct
    with obj1   = wa_usr07-objct
    with val101 = wa_usr07-val01
    with val111 = wa_usr07-val02
    with val121 = wa_usr07-val03
    with val131 = wa_usr07-val04
    with val141 = wa_usr07-val05
    with val151 = wa_usr07-val06
    with val161 = wa_usr07-val07
    with val171 = wa_usr07-val08
    with val181 = wa_usr07-val09
    with val191 = wa_usr07-val10
     via selection-screen
     and return
         .
  perform simulate_sapgui_update.
endform. "WHERE_USED
*-----------------------------------------------------------------------
form where_used_in_users.
  perform where_used using 'RSUSR002' 'SAP&_WERTE'.
endform. "WHERE_USED_IN_USERS
*-----------------------------------------------------------------------
form where_used_in_roles.
  perform where_used using 'RSUSR070' 'SAP&_VALUES'.
endform. "WHERE_USED_IN_ROLES
*-----------------------------------------------------------------------
form simulate_auth_check.
* if p_mandt <> sy-mandt.
**  app_log_z2_1 '092' p_mandt.
**-'The program you've try to call cannot work with data from client &.'
**  message i092 with p_mandt.
*   exit.
* endif.

  clear fail_subrc.
  call function 'SUSR_AUTHORITY_CHECK_SIMULATE'
       exporting

*-->>>---for SAP ERP 2005 --------------------------------------------*
*        new_buffering   = new_buffering
*-->>>----------------------------------------------------------------*

         user_name       = sel_bname
         object          = usr07-objct

*-->>>---for SAP R/3 Enterprise (4.7), SAP ERP, etc ------------------*
*        dummyvalues     = '0000' " 'FFFF' for Unicode
*-->>>----------------------------------------------------------------*

         field1          = usr07-fiel1
         val1            = usr07-val02
         field2          = usr07-fiel2
         val2            = usr07-val03
         field3          = usr07-fiel3
         val3            = usr07-val04
         field4          = usr07-fiel4
         val4            = usr07-val05
         field5          = usr07-fiel5
         val5            = usr07-val06
         field6          = usr07-fiel6
         val6            = usr07-val07
         field7          = usr07-fiel7
         val7            = usr07-val08
         field8          = usr07-fiel8
         val8            = usr07-val09
         field9          = usr07-fiel9
         val9            = usr07-val10
         field0          = usr07-fiel0
         val0            = usr07-val01
       importing
         sy_subrc        = fail_subrc
       exceptions
         not_authorized  = 1
         user_not_exists = 2
         internal_error  = 3
         others          = 4
         .
* if sy-subrc <> 0.
*   fail_subrc = 77.
**  message id sy-msgid type sy-msgty number sy-msgno
**     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* endif.
endform. "SIMULATE_AUTH_CHECK
*-----------------------------------------------------------------------
form fill_request using v_mandt like usr02-mandt
                        v_bname like usr02-bname
                        .
  data v_request like sy-repid value 'ZREQUEST_TO_CHANGE_SAPUSER'.

  if v_mandt <> sy-mandt.
    app_log_z2_1 '092' v_mandt.
*--'The program you've try to call cannot work with data from client &.'
    message s092 with v_mandt.
    exit.
  endif.

*-Check program existence and type
  is_executable v_request.

*-Progress indicator may be omitted when submitting VIA SELECTION-SCREEN
  perform issue_run_message using v_request 'X'.
  submit (v_request)
    with p_bname =  v_bname
    with p_usr07 = 'X'
    with p_manua = ' '
     via selection-screen
     and return
         .
  perform simulate_sapgui_update.
endform. "FILL_REQUEST
*-----------------------------------------------------------------------
form show_fail_hist using v_mandt like usr02-mandt
                          v_bname like usr02-bname
                          .
  data v_failhist like sy-repid value 'ZUSR07_USER'.

*-Check program existence and type
  is_executable v_failhist.

*-Progress indicator may be omitted when submitting VIA SELECTION-SCREEN
  perform issue_run_message using v_failhist 'X'.
  submit (v_failhist)
    with p_mandt = v_mandt
    with p_bname = v_bname
*    via selection-screen
     and return
         .
  perform simulate_sapgui_update.
endform. "SHOW_FAIL_HIST
*-----------------------------------------------------------------------
form show_last_fail using v_mandt like usr02-mandt
                          v_bname like usr02-bname
                          .
  data v_fail like sy-repid value 'ZSU53_USER'.

  if v_mandt <> sy-mandt.
    app_log_z2_1 '086' v_mandt.
*--'To take a look at this failure please logon in client &'
    message s086 with v_mandt.
    exit.
  endif.

*-Check program existence and type
  is_executable v_fail.

  perform issue_run_message using v_fail 'X'.
  submit (v_fail) with p_bname = v_bname and return.
  perform simulate_sapgui_update.
endform. "SHOW_LAST_FAIL
*-----------------------------------------------------------------------
form delete_entry_from_usr07 using v_mandt like usr07-mandt
                                   v_bname like usr07-bname
                                   .
* select single * from usr07 client specified
*                 where mandt = v_mandt
*                   and bname = v_bname
*                       .
* if sy-subrc <> 0.
*   perform simulate_sapgui_update.
*   exit.
* endif.

  if enable_chk1 = 'X'.
    case sy-uname.
      when sapstar
        or admin_1
        or admin_2
        or admin_3
        or admin_4
        or admin_5
        or admin_6
        or admin_7
        or admin_8
        or admin_9
           .
      when others.  app_log 'SH' '400' space space space space.
*------------------'Access refused'
                    message e400(sh).
    endcase.
  endif.

  concatenate 'Entry in table USR07:'(109)
               v_mandt
               v_bname
               usr07-objct
         into  pop_txt
               separated by space
               .
  confirm_step
    'N'
    'Are you sure this entry is obsolete and need to be removed'(099)
     pop_txt
    'Confirm deletion'(108)
     .
  if ans = 'J'.
    delete from usr07 client specified
           where mandt = v_mandt
             and bname = v_bname
                 .
    commit work.
    if sy-subrc <> 0.
      app_log 'MO' '426' space space space space.
*----'Error when deleting database record'
      message e426(mo).
    else.
      perform simulate_sapgui_update.
    endif.
  else. perform action_cancelled. endif.
endform. "DELETE_ENTRY_FROM_USR07
*-----------------------------------------------------------------------
form show_spool using v_mandt like usr02-mandt
                      v_bname like usr02-bname
                      .
  data v_spool like sy-repid value 'ZSP01_USER'.

*-Check program existence and type
  is_executable v_spool.

  perform issue_run_message using v_spool 'X'.
  submit (v_spool)
    with p_mandt = v_mandt
    with p_bname = v_bname
     and return
         .
  perform simulate_sapgui_update.
endform. "SHOW_SPOOL
*-----------------------------------------------------------------------
form show_user_locks using v_mandt like usr02-mandt
                           v_bname like usr02-bname
                           .
  data v_locks like sy-repid value 'ZSM12_USER'.

*-Check program existence and type
  is_executable v_locks.

  perform issue_run_message using v_locks 'X'.
  submit (v_locks)
    with p_mandt = v_mandt
    with p_bname = v_bname
     and return
         .
  perform simulate_sapgui_update.
endform. "SHOW_USER_LOCKS
*-----------------------------------------------------------------------
form call_sm04_user using v_bname like usr02-bname.
  data v_sm04 like sy-repid value 'ZSM04_USER'.

*-Check program existence and type
  is_executable v_sm04.

  perform issue_run_message using v_sm04 'X'.
  submit (v_sm04)
    with p_bname = v_bname
     and return
         .
  perform simulate_sapgui_update.
endform. "CALL_SM04_USER
*-----------------------------------------------------------------------
form call_sm50_user using v_bname like usr02-bname.
  data v_sm50 like sy-repid value 'ZSM50_USER'.

*-Check program existence and type
  is_executable v_sm50.

  perform issue_run_message using v_sm50 'X'.
  submit (v_sm50)
    with p_bname = v_bname
     and return
         .
  perform simulate_sapgui_update.
endform. "CALL_SM50_USER
*-----------------------------------------------------------------------
form query_user_copy using v_bname1 like usr02-bname
                           v_bname2 like usr02-bname
                           .
  data:
    new_bname like usr02-bname
  , title(40)
  .
  title = 'Copy & to'(791).
  replace amp with v_bname1 into title. condense title.
  call function 'POPUP_TO_GET_VALUE'
       exporting
         fieldname           = 'BNAME'
         tabname             = 'USR02'
         titel               =  title
         valuein             =  v_bname2
       importing
         answer              =  ans
         valueout            =  new_bname
       exceptions
         fieldname_not_found =  1
         .
  if sy-subrc = 0 and ans = space.
    if not new_bname is initial.
      call function 'USER_EXISTS'
           exporting
             bname           = new_bname
*          importing
*            locked          =
           exceptions
             user_exists     = 1
             user_dont_exist = 2
             others          = 3
             .
      case sy-subrc.
        when 1.       app_log '01' '224' new_bname space space space.
*--------------------'User & already exists'
                      message e224(01) with new_bname.
        when others.  perform copy_user using v_bname1 new_bname.
      endcase.
    endif.
  endif.
endform. "QUERY_USER_COPY
*-----------------------------------------------------------------------
form copy_user using v_bname1 like usr02-bname
                     v_bname2 like usr02-bname
                     .
  data:
    v_copy_user like sy-repid value 'ZSU01_COPY_USER'
* , passwd(8)
  .
*-Check program existence and type
  is_executable v_copy_user.

  perform issue_run_message using v_copy_user 'X'.
  submit (v_copy_user)
    with p_bname1 =  v_bname1
    with p_bname2 =  v_bname2
*   with p_refusr = 'X' " <-- set by default
*   with p_class  = 'X' " <-- set by default
*   with p_usrfav = 'X' " <-- set by default
     and return
         .
* import passwd from memory id 'NEW_PWD'.
* message i031 with 'Initial Password:' passwd.
  perform simulate_sapgui_update.
endform. "COPY_USER
*-----------------------------------------------------------------------
define macro_delete_user.
  perform issue_run_message using v_delete_user 'X'.
  submit (v_delete_user)
    with p_bname  =  v_bname
    with p_prompt = 'X'
     and return
         .
  perform simulate_sapgui_update.
end-of-definition. "MACRO_DELETE_USER
*-----------------------------------------------------------------------
form delete_user using v_bname like usr02-bname.
  data:
    v_delete_user like sy-repid value 'ZSU01_DELETE_USER'
  , tmp(70)
  .
*-Check program existence and type
  is_executable v_delete_user.

  select count( * ) from usrefus where refuser = v_bname.
  if sy-dbcnt > 0.
    move sy-dbcnt to s_dbcnt. condense s_dbcnt.
    concatenate: 'Other users have reference to'(949) v_bname
           into   tmp
                  separated by space
               ,  s_dbcnt 'link(s) found. Continue anyway?'(950)
           into   pop_txt
                  separated by space
                  .
    confirm_step 'N'
                  tmp
                  pop_txt
                 'There are links from other users'(951)
                  .
    if ans = 'J'. macro_delete_user. endif.
  else. macro_delete_user. endif.
endform. "DELETE_USER
*-----------------------------------------------------------------------
form show_roles_ex using v_mandt like sy-mandt
                         v_bname like usr02-bname
                         v_all_roles
                         .
  data v_roles like sy-repid value 'ZROLE_LIST'.
  ranges r_agrn for agr_define-agr_name.

*-All roles or Z-roles only?
  if v_all_roles is initial.
    r_agrn-low    = 'Z*'.
    r_agrn-sign   = 'I'.
    r_agrn-option = 'CP'.
    append r_agrn.
  else.
    refresh r_agrn.
  endif.

*-Check program existence and type
  is_executable v_roles.

*-Run without any prompt-----------------------------------------*
  perform issue_run_message using v_roles 'X'.
  submit (v_roles)
    with so_mandt-low =  v_mandt
    with so_agrn      in r_agrn
    with p_all        = ' '
    with p_assign     = 'X'
    with p_dummy      = ' '
    with p_edit       = 'X'
    with p_short      = 'X'
    with so_bname-low =  v_bname
    with p_usemyn     = 'X'
    with p_mynote     =  v_bname
     and return
         .
  perform simulate_sapgui_update.
endform. "SHOW_ROLES_EX
*-----------------------------------------------------------------------
form show_roles.
  data:
    p_rc
  , v_mandt like sy-mandt
  , v_bname like sy-uname
  , v_title(70)
  .
  v_mandt = p_mandt.
  v_bname = sel_bname.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

*-Rebuild table for POPUP_GET_VALUES:
  a_flds 'USR02'
         'BNAME'
         'User'(202)         " BNAME (User)
          v_bname
          .
  a_flds 'T000'
         'MANDT'
         'Client'(011)       " Client
          v_mandt
          .
  if f_ar is initial.
    v_title = 'Display Z-roles assigned to user'(229).
  else.
    v_title = 'Display all roles assigned to user'(164).
  endif.

  clear p_rc.
  call function 'POPUP_GET_VALUES_USER_HELP'
       exporting
         popup_title     =  v_title
         f4_formname     = 'F4_HELP_POPUP'
         f4_programname  =  sy-cprog
       importing
         returncode      =  p_rc
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if p_rc <> 'A'.
    r_flds 01 v_bname.
    r_flds 02 v_mandt.
    perform show_roles_ex using v_mandt v_bname f_ar.
  else.
    perform action_cancelled.
  endif.

  free fields.
endform. "SHOW_ROLES
*-----------------------------------------------------------------------
form show_roles_main.
* check_mark_exists.
* if sy-subrc = 0.
*   confirm_step 'Y'
*                'Do you want to display roles'
*                'of selected users?'
*                'View roles'
*                 .
*   if ans = 'J'.
*     perform show_roles_mass.
*   else.
*     perform action_cancelled.
*   endif.
* else.
    get_and_check_sel_bname.
    perform show_roles_ex using p_mandt sel_bname f_ar.
* endif.
endform. "SHOW_ROLES_MAIN
*-----------------------------------------------------------------------
form get_trace_state.
  perform read_swb.
  perform read_mod.
endform. "GET_TRACE_STATE
*-----------------------------------------------------------------------
form read_swb.                                      "Source: RSTRAC25
  clear switchbuf.

  call 'C_GET_SWITCH'
    id 'TST21' field switchbuf
    .
  if sy-subrc = 2.
    f_main_off = 'X'.
  elseif switchbuf-sw_auth is initial.
    f_main_off = ' '.
    f_auth_off = 'X'.
  else.
    f_main_off = ' '.
    f_auth_off = ' '.
  endif.
endform. "READ_SWB
*-----------------------------------------------------------------------
form read_mod.                                      "Source: RSTRAC25
  call 'C_GET_MOD_TIME'
    id 'USER'    field mod_user
    id 'TIME'    field mod_time
*   id 'POS'     field rstrtype-pos
*   id 'MAXSIZE' field rstrtype-maxsize
*   id 'WRAP'    field rstrtype-wrap
    .
  if sy-subrc <> 0.
    if sy-subrc = 4.
      move  'SCSA.SWB'  to mod_user.
      move  'missing !' to mod_time.
*     move  ' '         to can_use_scsa_swb.
    else.
      move  '?'         to mod_user.
      write  sy-subrc   to mod_user+1.
    endif.
  endif.
  concatenate mod_user mod_time
         into sw_change
              separated by space
              .
endform. "READ_MOD
*-----------------------------------------------------------------------
form user_trace using bname like usr02-bname.
  data v_trace like sy-repid value 'ZRSTRAC21'.

*-Check program existence and type
  is_executable v_trace.

* perform read_swb(rstrac25) if found using switchbuf.
  perform get_trace_state.
  concatenate sw_change 'Run report anyway?'(972)
         into pop_txt
              separated by space
              .
  if     f_main_off = 'X'.
*   app_log 'TC' '021' space space space space.
*--'Trace disabled in system: Unable to read switch'
*   message i021(tc). "Trace is switched off. Cannot read switches.
    confirm_step 'N'
                 'Trace is switched off. Cannot read switches.'(969)
                  pop_txt
                 'ST01 - trace currently disabled'(970)
                  .
    if ans <> 'J'.
      perform action_cancelled.
      exit.
    endif.
  elseif f_auth_off = 'X'.
*   app_log_z2_0 '075'.
*--'Authorization check is not active! (see transaction ST01)'
*   message i075.
    confirm_step 'N'
                 'Authorization check is not active!'(971)
                  pop_txt
                  text-970
                  .
    if ans <> 'J'.
      perform action_cancelled.
      exit.
    endif.
  endif.
*-Run with prompt------------------------------------------------*
* perform confirm_program_run using v_trace.
* case ans.
*   when 'J'. submit (v_trace) with tr_user = bname and return.
* endcase.

*-Run without any prompt-----------------------------------------*
  perform issue_run_message using v_trace 'X'.
  submit (v_trace) with tr_user = bname and return.
  perform simulate_sapgui_update.
endform. "USER_TRACE
*-----------------------------------------------------------------------
*form user_trace_47 using v_mandt like sy-mandt
*                         v_bname like usr02-bname
*                                 .
*  data:
*    v_trace    like sy-repid value 'RSTRAC22'
*  , resp       type i              "Minutes
*  , start_date like sy-datum
*  , start_time like sy-uzeit
*  .
**-Check program existence and type
*  is_executable v_trace.
*
** perform read_swb(rstrac25) if found using switchbuf.
*  perform get_trace_state.
*  concatenate sw_change 'Run report anyway?'(972)
*         into pop_txt
*              separated by space
*              .
*  if     f_main_off = 'X'.
**   app_log 'TC' '021' space space space space.
**--'Trace disabled in system: Unable to read switch'
**   message i021(tc). "Trace is switched off. Cannot read switches.
*    confirm_step 'N'
*                 'Trace is switched off. Cannot read switches.'(969)
*                  pop_txt
*                 'ST01 - trace currently disabled'(970)
*                  .
*    if ans <> 'J'.
*      perform action_cancelled.
*      exit.
*    endif.
*  elseif f_auth_off = 'X'.
*    app_log_z2_0 '075'.
**--'Authorization check is not active! (see transaction ST01)'
**   message i075.
*    confirm_step 'N'
*                 'Authorization check is not active!'(971)
*                  pop_txt
*                  text-970
*                  .
*    if ans <> 'J'.
*      perform action_cancelled.
*      exit.
*    endif.
*  endif.
*
*  resp = 30.                         "Minutes
*  start_date = sy-datum.
*  start_time = sy-uzeit - resp * 60.
*  if start_time > sy-uzeit. subtract 1 from start_date. endif.
*
**-Run without any prompt-----------------------------------------*
*  submit (v_trace)
**   with filename =
*    with user     = v_bname
*    with client   = v_mandt
*    with datum    = start_date
*    with zeit     = start_time
*    with to_date  = sy-datum
*    with to_time  = sy-uzeit
*    with resptime = resp
**   with tabfunc  = ' '
**   with table1   = ' '
**   with table2   = ' '
**   with table3   = ' '
**   with table4   = ' '
**   with table5   = ' '
*    with sql_recs = ' '
*    with aut_recs = 'X'
*    with enq_recs = ' '
*    with tbf_recs = ' '
*    with rfc_recs = ' '
*    with cmd_recs = ' '
*    with usr_recs = ' '
*    with maxrecs  = 90000
*     and return
*    .
*endform. "USER_TRACE_47
*-----------------------------------------------------------------------
form stat_records using bname like usr02-bname.
  data:
    p_rc       type c
  , tmp        like sy-uzeit

  , ruser      like sapwlpfnrm-account       "User
  , rtcode     like sapwlpfnrm-tcode         "Tcode
  , rprogram   like sapwlpfnrm-report        "Report
* , tasktype                                 "Task type
  , rscreen    like sapwlpfnrm-dynpronr      "Dynpro
* , rwpid(2)                                 "Work Process

  , rrspti     like sapwlpfidx-max_respti    "Resp. time
  , rdbti      like sapwlpfidx-max_dbti      "DB time
  , rcputi     like sapwlpfidx-max_cputi     "CPU time
* , rkbyte     type i                        "Bytes trans
* , rchg       type i                        "Phys.Aenderg.

  , rstartti   like sy-uzeit                 "Start time
  , rday       like sy-datum                 "Start day
  , rendti     like sy-uzeit
  , rendday    like sy-datum

  , rpath      like sapwlpstrc-filename      "Stat. Dataset name
  , rmaxcnt    like statl-smaxcnt value 500  "Max number of
  .                                          "    shown entries
*-If user has no authority to read system trace
  if auth_st0r is initial.
    app_log_00_1 '149' obj_sysadm.
*--'You haven't authorization for object &'
    message e149(00) with obj_sysadm.
*   exit.
  endif.

*-Fill default values
  if bname is initial. ruser = '*'. else. ruser = bname. endif.
  rtcode   = '*'.             "Transaction mask = all
  rprogram = '*'.             "Program     mask = all
  rscreen  = '*'.             "Dynpro      mask = all
  rrspti   =  space.          "Response time limitation
  rdbti    =  space.          "Database time limitation
  rcputi   =  space.          "CPU      time limitation

  if p_stat2h = 'X'.
    tmp = rstartti = sy-uzeit.       "Set time to Now
    rstartti =  rstartti - 120 * 60. "Turn clock back for 2 hours
    if rstartti > tmp.               "Time overflow occured?
      rday     =  sy-datum - 1.      "Start day - Yesterday
    else.
      rday     =  sy-datum.          "Start day - Today
    endif.
  else.
    rstartti = '090000'.      "Start time = 09:00:00
    rday     =  sy-datum.     "Start day  = today
  endif.

  rendti   =  sy-uzeit.       "End   time = now
  rendday  =  sy-datum.       "End   day  = today
  rmaxcnt  =  1000.           "Select up to 1000 records

*-Read parameter value 'stat/file' from instance (or default) profile
  get_param 'stat/file' rpath.
  if sy-subrc > 0 or rpath is initial.
    app_log 'S1' '097' 'stat/file' rpath space space.
*--'No statistics available (Profile & is set to &)'
    message e097(s1) with 'stat/file' rpath.
*   exit.
  endif.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

*-Rebuild table for POPUP_GET_VALUES:
  a_flds 'SAPWLPFNRM'
         'ACCOUNT'
          text-202   " BNAME (User)
          ruser
          .
  a_flds 'STATL'
         'SMAXCNT'
         'Max. number of shown entries'(412)
          rmaxcnt
          .
  a_flds 'SYST'
         'UZEIT'
         'Since time (hhmmss)'(407)
          rstartti
          .
  a_flds 'SYST'
         'DATUM'
         'Since day (incl.)'(408)
          rday
          .
* a_flds '*SYST' " we use * as a prefix to avoid duplicate fields!
*        'UZEIT'
*        'Until time (hhmmss)'(409)
*         rendti
*         .
* a_flds '*SYST' " we use * as a prefix to avoid duplicate fields!
*        'DATUM'
*        'Until day (incl.)'(410)
*         rendday
*         .
  a_flds 'SAPWLPFNRM'
         'TCODE'
          text-025   "   'Transaction'(401)
          rtcode
          .
  a_flds 'SAPWLPFNRM'
         'REPORT'
         'Program__'(402)
          rprogram
          .
  a_flds 'SAPWLPFNRM'
         'DYNPRONR'
         'Screen number'(403)
          rscreen
          .
  a_flds 'SAPWLPFIDX'
         'MAX_RESPTI'
         'Resp. time (ms) >='(404)
          rrspti
          .
  a_flds 'SAPWLPFIDX'
         'MAX_DBTI'
         'DB req time (ms) >='(405)
          rdbti
          .
* a_flds 'SAPWLPFIDX'
*        'MAX_CPUTI'
*        'CPU time (ms) >='(406)
*         rcputi
*         .
*-Field SAPWLPSTRC-FILENAME is to long (100 chars) for POPUP,
* therefore we have use RV60A-PAMSG (64 chars)
  a_flds 'RV60A'               "    'SAPWLPSTRC'.
         'PAMSG'               "    'FILENAME'.
         'Seq. stat. dataset name'(411)
          rpath
          .
  clear p_rc.
  call function 'POPUP_GET_VALUES'
       exporting
         popup_title     = 'Single statistical records'(400)
       importing
         returncode      =  p_rc
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if p_rc <> 'A'.
    r_flds 01 ruser.
    r_flds 02 rmaxcnt.
    r_flds 03 rstartti.
    r_flds 04 rday.
*   r_flds ?? rendti.
*   r_flds ?? rendday.
    r_flds 05 rtcode.
    r_flds 06 rprogram.
    r_flds 07 rscreen.
    r_flds 08 rrspti.
    r_flds 09 rdbti.
*   r_flds ?? rcputi.
    r_flds 10 rpath.

    perform issue_run_message using 'RSSTAT20' 'X'.

*   set parameter id 'XUS' field sel_bname.
*   submit rsstat20 via selection-screen and return.
    submit rsstat20
      with ruser    = ruser
      with rtcode   = rtcode
      with rprogram = rprogram
      with rscreen  = rscreen
      with rrspti   = rrspti
      with rdbti    = rdbti
      with rcputi   = rcputi
      with rstartti = rstartti
      with rday     = rday
      with rendti   = rendti
      with rendday  = rendday
      with rpath    = rpath
      with rmaxcnt  = rmaxcnt
       and return
           .
  endif.

  free fields.
  perform simulate_sapgui_update.
endform. "STAT_RECORDS
*-----------------------------------------------------------------------
form create_slave using utid like uinfo-tid.
* check utid <> 0.
  if utid is initial.
    app_log_z2_0 '037'.
*--'Terminal ID = 0, request will be ignored!'.
    message e037. "exit.
  endif.
  call 'ThUsrInfo'
    id 'OPCODE' field opcode_create_slave
    id 'S_TID'  field utid
    id 'S_MODE' field slave_mode
    .
  app_log_z2_1 '034' utid.
*-'Request on slave creation on terminal & transferred to kernel'
  message s034 with utid.
endform. "CREATE_SLAVE
*-----------------------------------------------------------------------
form remove_slave using utid like uinfo-tid.
* check utid <> 0.
  if utid is initial.
    app_log_z2_0 '037'.
*--'Terminal ID = 0, request will be ignored!'.
    message e037. "exit.
  endif.
* slave_mode = 5.
  call 'ThUsrInfo'
    id 'OPCODE' field opcode_remove_slave
    id 'S_TID'  field utid
*   id 'S_MODE' field slave_mode
    .
  app_log_z2_1 '035' utid.
*-'Slave on terminal & removed (if present)'
  message s035 with utid.
endform. "REMOVE_SLAVE
*-----------------------------------------------------------------------
define ask_about.
  data:
    ans
  , title  like spop-titel
  , termid like usr41-termid
  .
  release_check.

  move &1 to title.
  perform read_termid_and_query_continue using title
                                      changing termid
                                               ans
                                               .
end-of-definition. "ASK_ABOUT
*-----------------------------------------------------------------------
form create_slave_selected.
  ask_about 'Create slave on terminal'(415).
  if ans <> 'A'. perform create_slave using termid. endif.
endform. "CREATE_SLAVE_SELECTED
*-----------------------------------------------------------------------
form remove_slave_selected.
* ask_about 'Remove slave on terminal'(416).
* if ans <> 'A'. perform remove_slave using termid. endif.

  app_log_z2_0 '091'.
*-'To remove ECHO just close window from where you have set it ON'
  message i091.
endform. "REMOVE_SLAVE_SELECTED
*-----------------------------------------------------------------------
form read_termid_and_query_continue using title
                                 changing termid like uinfo-tid
                                          ans
                                          .
  ans = 'A'.
  check sy-pfkey = 'USER'. clear usr41-termid.

  read current line field value usr41-termid.
  if ( sy-subrc <> 0 ) or ( usr41-termid is initial ).
    app_log_z2_0 '036'.
*--'Place cursor on terminal ID!'
    message e036. "exit.
  endif.

  move usr41-termid to termid.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  a_flds 'UINFO'
         'TID'
         'Terminal ID'(417)
          termid
          .
* clear ans.
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     =  title
         start_column    =  41
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'. r_flds 1 termid. endif.
  free fields.
endform. "READ_TERMID_AND_QUERY_CONTINUE
*-----------------------------------------------------------------------
* Call transaction on remote server
form remote_transaction using l_tcode like sm04dic-tcode1
                              l_dest  like msxxlist-name.
  data:
    comm_message(256)
  , syst_message(256)                                   "#EC NEEDED
  .
  if l_tcode is initial.
    app_log_z2_2 '031' text-800 sy-repid.
*---Just a warning on empty TCODE
    message i031 with
      'There are no transaction code associated with'(800) sy-repid.
  endif.

  if l_dest = myname.
*---Prevent calling empty TCODE locally
*   if not l_tcode is initial.
*     perform call_transaction using l_tcode.
*   endif.

*---------------------'You are already logged on server'
    app_log_z2_2 '031' text-785 l_dest.
    message s031 with text-785 l_dest.
  else.
    concatenate 'Connecting to'(926) l_dest
           into  pop_txt
                 separated by space
                 .
    condense pop_txt.

    progress_ind pop_txt.
*---Call remote TCODE or just RFC-logon, if TCODE is empty
    call function 'TH_REMOTE_TRANSACTION'
         exporting
           dest         = l_dest
           tcode        = l_tcode
         importing
           comm_message = comm_message
           syst_message = syst_message
           .
    if comm_message ne space.
      app_log '14' '102' l_dest comm_message space space.
*----'Communication error with server & : &'
      message s102(14) with l_dest comm_message.
    else.
      perform simulate_sapgui_update.
    endif.
  endif.
endform. "REMOTE_TRANSACTION
*-----------------------------------------------------------------------
form report_p_refr_status.
  if p_refr is initial.
    app_log_z2_0 '102'.
*--'Refresh-on-Return: Deactivated'
    message s102.
  else.
*--'Refresh-on-Return: Activated'
    app_log_z2_0 '103'.
    message s103.
  endif.
endform. "REPORT_P_REFR_STATUS
*-----------------------------------------------------------------------
form compute_threshold_date.
*-Set threshold date depending on P_PERIOD
  x_datum = sy-datum - p_period.
  write x_datum to s_datum using edit mask d_mask.
endform. "COMPUTE_THRESHOLD_DATE
*-----------------------------------------------------------------------
form compute_threshold_period.
*-Set threshold period depending on X_DATUM
  p_period = sy-datum - x_datum.
* write x_datum to s_datum using edit mask d_mask.
endform. "COMPUTE_THRESHOLD_PERIOD
*-----------------------------------------------------------------------
form report_threshold_date.
  app_log_z2_2 '031' text-261 x_datum.
  message s031 with 'Threshold date is'(261) x_datum.
endform. "REPORT_THRESHOLD_DATE
*-----------------------------------------------------------------------
form set_period_ex using new_value.
  move new_value to p_period.
  perform compute_threshold_date.
  perform print_list_as_is.
  perform report_threshold_date.
endform. "SET_PERIOD_EX
*-----------------------------------------------------------------------
form set_period.
  ans = 'A'.
  check sy-pfkey = 'MAIN'.

  cls fields.
  a_flds   'CCPARPARM'   "  'RSEUMOD'
           'COUNTER'     "  'TBLISTBR'
           'Days from last logon'(902)
            p_period
            .
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     = 'Enter threshold value'(903)
         start_column    =  41
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'.
    read table fields index 1.
    if fields-value <> p_period.
      perform set_period_ex using fields-value.
    endif.
  endif.
  free fields.
endform. "SET_PERIOD
*-----------------------------------------------------------------------
form set_threshold_date_ex using v_datum.
  x_datum = v_datum.
  perform compute_threshold_period.
  perform print_list_as_is.
  perform report_threshold_date.
endform. "SET_THRESHOLD_DATE_EX
*-----------------------------------------------------------------------
form set_threshold_date.
  data:
    cur_value like workflds-gkday
  , new_value like cur_value
  .
  check sy-pfkey = 'MAIN'.

  move x_datum to cur_value.

  call function 'F4_DATE'
       exporting
         date_for_first_month               = cur_value
*        display                            = ' '
*        factory_calendar_id                = ' '
*        gregorian_calendar_flag            = ' '
*        holiday_calendar_id                = ' '
*        progname_for_first_month           = ' '
       importing
         select_date                        = new_value
*        select_week                        =
*        select_week_begin                  =
*        select_week_end                    =
       exceptions
         calendar_buffer_not_loadable       = 1
         date_after_range                   = 2
         date_before_range                  = 3
         date_invalid                       = 4
         factory_calendar_not_found         = 5
         holiday_calendar_not_found         = 6
         parameter_conflict                 = 7
         others                             = 8
         .
  if sy-subrc <> 0.
    message id 'S' type sy-msgty number sy-msgno
       with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  else.
    if     new_value  > sy-datum.
      app_log_z2_0 '104'.
*----'Threshold date must NOT be in the future'
      message s104.
    elseif new_value <> x_datum and not new_value is initial.
      perform set_threshold_date_ex using new_value.
    endif.
  endif.
endform. "SET_THRESHOLD_DATE
*-----------------------------------------------------------------------
form get_keepalive changing value(keepalive).
*-Documentation on this system profile parameter from transaction RZ11:
* This parameter specifies the maximum time (in sec.) the system waits
* after a period of inactivity (no data transferred) in a CPIC
* connection before sending a ping to check if the partners
* are still active. Value of 0 deactivates check.

*-Get 'rdisp/keepalive' value (Timer for check unused connections)
* get_param s_keepal keepalive.
endform. "GET_KEEPALIVE
*-----------------------------------------------------------------------
form user_enqueue using p_bname rc.
  data v1 like sy-msgv1.

  call function 'ENQUEUE_E_USR04'
       exporting
*        mode_usr04     = 'X' "Note 198339; use default MODE='E'
         bname          =  p_bname
       exceptions
         foreign_lock   =  1
         system_failure =  2
         .
  rc = sy-subrc.
  v1 = sy-msgv1. "Save sy-msgv1: else it will be lost! Is there a bug?!
  case sy-subrc.
    when 0.
    when 1.
      app_log '01' '410' p_bname v1 space space.
*----'Maintenance of user &1 locked by user &2'
      message i410(01) with p_bname v1.
    when 2.
      app_log '01' '413' space space space space.
*---'System lock administration error. Please notify your administrator'
      message i413(01).
  endcase.
endform. "USER_ENQUEUE
*-----------------------------------------------------------------------
form user_dequeue using p_bname p_addrnumber.
  call function 'DEQUEUE_E_USR04'
       exporting
*        mode_usr04 = 'X' "Note 198339; use default MODE='E'
         bname      =  p_bname
         .
  call function 'ADDR_DEQUEUE'
       exporting
         address_number    =  p_addrnumber
         mode_adrc         = 'S'
*        _scope            = '3'
*        _synchron         = ' '
*        _collect          = ' '
       exceptions
         address_not_exist =  1
         internal_error    =  2
         others            =  3
         .
  if sy-subrc <> 0.
*   if not sy-msgty is initial.
*     message id sy-msgid     type sy-msgty number sy-msgno
*           with sy-msgv1 sy-msgv2 sy-msgv3        sy-msgv4.
*   else.
*     message id sy-msgid     type   'S'    number sy-msgno
*           with sy-msgv1 sy-msgv2 sy-msgv3        sy-msgv4.
*   endif.
    app_log sy-msgid sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform. "USER_DEQUEUE
*-----------------------------------------------------------------------
form user_enqueue_mass tables p_users           structure ususers
                              p_users_locked    structure ususers
                              p_locked_by       structure ususers
                       using  p_num_locked      type i
                              p_rc              like sy-subrc
                              .
  refresh p_users_locked.
  p_rc = 0.
  loop at p_users.
    call function 'ENQUEUE_E_USR04'
         exporting
           bname          = p_users-bname
         exceptions
           foreign_lock   = 1
           system_failure = 2
           .
    case sy-subrc.
      when 0.
      when 1. p_users_locked-bname = p_users-bname.
              append p_users_locked.

              move sy-msgv1 to p_locked_by-bname.
              append p_locked_by.

              if p_rc <= 1. p_rc = 1. endif.

      when 2. p_rc = 2.
*---'System lock administration error. Please notify your administrator'
*             message i413.
    endcase.
  endloop.

  describe table p_users_locked lines p_num_locked.
  if p_num_locked <> 0.
    loop at p_users_locked.
      delete p_users where bname = p_users_locked-bname.
    endloop.
  endif.
endform. "USER_ENQUEUE_MASS
*-----------------------------------------------------------------------
form user_dequeue_mass tables p_users structure ususers.
  loop at p_users.
    call function 'DEQUEUE_E_USR04'
         exporting
           bname = p_users-bname
           .
  endloop.
endform. "USER_DEQUEUE_MASS
*-----------------------------------------------------------------------
form insert_ush02 tables cd_users structure ususers.
  data:
    wa_usr02 like usr02
  , wa_ush02 like ush02
  , it_ush02 type standard table of ush02
  .
  loop at cd_users.
    clear:
      wa_usr02
    , wa_ush02
    .
    select single * from usr02
                    into wa_usr02
                    where bname = cd_users-bname
                          .
    if sy-subrc = 0.
      move:
        sy-mandt       to wa_ush02-mandt
      , sy-datum       to wa_ush02-modda
      , sy-uzeit       to wa_ush02-modti
      , sy-uname       to wa_ush02-modbe
      , sy-tcode       to wa_ush02-tcode
      , sy-repid       to wa_ush02-repid
      , wa_usr02-bname to wa_ush02-bname
      , wa_usr02-bcode to wa_ush02-bcode
      , wa_usr02-gltgv to wa_ush02-gltgv
      , wa_usr02-gltgb to wa_ush02-gltgb
      , wa_usr02-ustyp to wa_ush02-ustyp
      , wa_usr02-class to wa_ush02-class
      , wa_usr02-uflag to wa_ush02-uflag
      , wa_usr02-accnt to wa_ush02-accnt
      .
      append wa_ush02 to it_ush02.
    endif.
  endloop.
  insert ush02 from table it_ush02 accepting duplicate keys.
endform. "INSERT_USH02
*-----------------------------------------------------------------------
form lock_unlock_user using s       like st_it
                            l_uflag type x
                            .
  data:
    rc         like sy-subrc
  , force_mode
  , cd_users   type standard table of ususers with header line
  .
  define exit_if_cancelled.
    if ans <> 'J'.
      perform action_cancelled.
      exit.
    endif.
  end-of-definition. "EXIT_IF_CANCELLED

*-Do nothing if current flag identical with new value
  if s-uflag = l_uflag.
    app_log_z2_2 '031' s-bname text-989.
    message s031 with s-bname '- Lock state not changed'(989).
    exit.
  endif.

*-Check for special untouched status of the user
* if s-uflag <> c_not_locked             and
*    s-uflag <> c_locked_by_admin        and
*    s-uflag <> c_locked_by_global_admin and
*    s-uflag <> c_locked_by_failed_logon
*    .
*   app_log_z2_1 '049' s-bname.
*--'User & is untouchable. Please, maintain this user manually'.
*   message i049 with s-bname.
*   exit.
* endif.

  clear usr02.
  select * from usr02 client specified
           where mandt = s-mandt
             and bname = s-bname
                 .
  endselect.

*-Check that user has authority to make these changes
  authority-check object obj_usradm
    id 'CLASS' field usr02-class
*   id 'CLASS' dummy
    id 'ACTVT' field '05'
    .
  if sy-subrc <> 0.
    app_log_00_0 '432'.
*--'No authorization for user administration'
    message e432(00).
*   if sy-subrc = 4.
**    write:
**    / 'You are not authorized to lock/unlock user'
**    ,  s-bname
**    ,  s-class
**    .
*   else.
**    write:
**    / 'Authorization error checking user '
**    ,  s-bname
*     ,  s-class
**    , '(return code'
**    ,  sy-subrc
**    , ').'
**    .
*   endif.
  else.                                "has authority
    if l_uflag = c_not_locked.
      pop_txt = 'Do you want to unlock user'(986).
    else.
      pop_txt = 'Do you want to lock user'(987).
    endif.
    confirm_step 'N'
                  pop_txt
                  s-bname
                 'Lock/unlock user'(988)
                  .
    exit_if_cancelled.

    if s-bname =  sy-uname and         "Do I want to lock myself? :)
       l_uflag <> c_not_locked.
      confirm_step 'N'
                   'You really want to lock yourself account'(917)
                    s-bname
                   'Self-locking confirmation'(918)
                    .
      exit_if_cancelled.
    endif.

    clear force_mode.
    perform user_enqueue using s-bname rc.
    if rc <> 0.
      force_mode = 'X'.
      confirm_step 'N'
                   'Do you want to force processing with user'(919)
                    s-bname
                   'Ignore Locks'(922)
                    .
      exit_if_cancelled.
    endif.

*---Set user flag
    update usr02 set uflag = l_uflag
*--------------------We do not want to clear incorrect logon counter!
*                    locnt = space
               where bname = s-bname
                     .
    if sy-subrc <> 0.
      app_log '01' '305' space space space space.
*----'Lock/unlock not possible'
      message i305(01).
    else.
      if l_uflag = c_not_locked.
        app_log '01' '246' s-bname space space space.
*------'User & unlocked, if this is permitted in this system'
        message s246(01) with s-bname.
      else.
        app_log '01' '245' s-bname space space space.
*------'User & locked'
        message s245(01) with s-bname.
      endif.

      refresh cd_users.
*     cd_users-bname = s-bname. append cd_users.
      append s-bname to cd_users.
*-----Create change document entry in tab. USH02
      perform insert_ush02 tables cd_users.
    endif.

*   call function 'SUSR_USER_ADDRESS_GET'
*        exporting
*          user_name           = s-bname
*        importing
*          user_address        = user_address
*        exceptions
*          user_name_not_exist = 1
*          others              = 2
*          .
*   case sy-subrc.
*     when 0.                         " all ok
*     when 1. clear user_address.
**    when 2. raise internal_error.
*   endcase.
    if force_mode is initial.
      perform user_dequeue using s-bname s-addrnumber.
    endif.

    perform refresh_list.
  endif.
endform. "LOCK_UNLOCK_USER
*-----------------------------------------------------------------------
form lock_unlock_selected_user using l_uflag type x.
  check_mark_exists.
  if sy-subrc = 0.
    case l_uflag.
      when c_not_locked.
           pop_txt = 'Do you want to unlock selected users?'(979).
      when c_locked_by_admin
        or c_locked_by_global_admin.
           pop_txt = 'Do you want to lock selected users?'(980).
      when others. exit.
    endcase.
    confirm_step 'N'
                  pop_txt
                 'Note: Special users will be excluded!'(981)
                 'Mass locking/unlocking'(982)
                  .
    if ans = 'J'.
      perform lock_unlock_mass using l_uflag.
    else.
      perform action_cancelled.
    endif.
  else.
    get_and_check_sel_bname.

    read table it with key bname = sel_bname.
    if sy-subrc = 0.
      perform lock_unlock_user using it l_uflag.
    endif.
  endif.
endform. "LOCK_UNLOCK_SELECTED_USER
*-----------------------------------------------------------------------
form lock_unlock_mass using p_uflag type x.
  data:
    ok_list(4)
  , str_enq(4)
  , str_noa(4)
  , num_locked like sy-tabix
  , num_noauth like sy-index
  , begin of log_list occurs 10
  ,   line(60)
  , end   of log_list
  .
  data begin of p_users          occurs occ_val.
         include structure ususers.
  data end   of p_users.

  data begin of p_users_locked   occurs occ_val.
         include structure ususers.
  data end   of p_users_locked.

  data begin of p_locked_by      occurs occ_val.
         include structure ususers.
  data end   of p_locked_by.

  data:
       begin of p_noauth         occurs occ_val
  ,      bname like usr02-bname
  ,      class like usr02-class
  ,    end   of p_noauth
  .
*----------------------------------------------------
define log_maintained.
  cls log_list.
  do num_locked times.
    read table p_users_locked index sy-index.
    read table p_locked_by    index sy-index.
    if sy-subrc = 0.
      write:
         icon_failure                to log_list-line+00(04)
      ,  p_users_locked-bname        to log_list-line+05(12)
      , 'is processing by user'(985) to log_list-line+18(28)
      ,  p_locked_by-bname           to log_list-line+48(12)
      .
      append log_list.
    endif.
  enddo.

  str_enq = num_locked. condense str_enq.
  set titlebar 'ENQ' with str_enq.
  call function 'SUSR_POPUP_LIST_WITH_TEXT'
       exporting
         text1   =
           'Maintenance of some users is not possible now.'(983)
         text2   =
    'These users will be excluded from further processing.'(984)
*        text3   = ''
*        text4   = ''
       importing
         ok_code = ok_list
       tables
         list    = log_list
         .
  if ok_list = 'CANC'.
*   append lines of p_users_locked to p_users.
*---Release locks after processing
    dequeue_mass.
    perform action_cancelled.
    exit.
  endif.
end-of-definition. "LOG_MAINTAINED
*----------------------------------------------------
define log_skipped_noauth.
  cls log_list.
  loop at p_noauth.
    write:
       icon_message_critical_small to log_list-line+00(04)
    ,  p_noauth-bname              to log_list-line+05(12)
    , 'Class'(353)                 to log_list-line+18(05)
    ,  p_noauth-class              to log_list-line+24(12)
    .
    append log_list.
  endloop.

  str_noa = num_noauth. condense str_noa.
  set titlebar 'NOA' with str_noa.
  call function 'SUSR_POPUP_LIST_WITH_TEXT'
       exporting
         text1   = 'You have not sufficient privilegies'(351)
         text2   = 'to lock/unlock these users'(352)
*        text3   = ''
*        text4   = ''
*      importing
*        ok_code = ok_list
       tables
         list    = log_list
         .
*  if ok_list = 'CANC'.
*    perform action_cancelled.
*    exit.
*  endif.
end-of-definition. "LOG_SKIPPED_NOAUTH
*----------------------------------------------------
*-Where tab for SQL
  ranges r_users for usr02-bname occurs occ_val.

*-Check authorizations at all
  authority-check object obj_usradm
*   id 'CLASS' field s-class <-- Not yet implemented
    id 'CLASS' dummy
    id 'ACTVT' field '05'
    .
  if sy-subrc <> 0.
    app_log_00_0 '432'.
*--'No authorization for user administration'
    message e432(00).
  endif.

  cls: p_users, p_users_locked, p_locked_by, p_noauth.

  define dequeue_mass.
*---Release locks after processing
*   perform user_dequeue_mass(saplsuu0) tables p_users.
    perform user_dequeue_mass           tables p_users.
  end-of-definition. "DEQUEUE_MASS

*-Prepare user list to be processed
  clear num_noauth.
  loop at it assigning <fs> where mark = 'X'.
*---Check authorizations to lock/unlock specific user
    authority-check object obj_usradm
      id 'CLASS' field <fs>-class
*     id 'CLASS' dummy
      id 'ACTVT' field '05'
      .
*    clear v_class.
*    select single class
*                  into v_class
*                  from usr02 where bname = <fs>-bname
*                       .
*    authority-check object obj_usradm
*      id 'CLASS' field v_class
**     id 'CLASS' dummy
*      id 'ACTVT' field '05'
*      .
    if sy-subrc = 0.
*-----Has authorization, add user to user list.
*     p_users-bname = <fs>-bname.
      append <fs>-bname to p_users.
    else.
*-----Increase failure due to insuff. privileges count
      add 1 to num_noauth.
      p_noauth-bname = <fs>-bname.
      p_noauth-class = <fs>-class.
      append p_noauth.
    endif.
  endloop.

*-Exclude special users from mass locking/unlocking
  delete p_users where bname in avoid.

*-Redundant check for safety :-)
  if p_users[] is initial.
*---Log users skipped due to unsufficient privileges if any
    if not num_noauth is initial. log_skipped_noauth. endif.
    exit.
  endif.

  cls r_users.
*-Set locks before processing
* perform user_enqueue_mass(saplsuu0) tables p_users
*                                            p_users_locked
*                                     using  num_locked
*                                            rc
*                                            .
  perform user_enqueue_mass           tables p_users
                                             p_users_locked
                                             p_locked_by
                                      using  num_locked
                                             rc
                                             .
  case rc.
    when 0.
    when 1. log_maintained.
    when 2. app_log '01' '413' space space space space.
*--'System lock administration error. Please notify your administrator'
            message e413(01).
  endcase.

*-Fill range table for mass processing
  loop at p_users.
    r_users-sign   = 'I'.
    r_users-option = 'EQ'.
    r_users-low    =  p_users-bname. append r_users.
  endloop.

*-Redundant check for safety :-)
  if not r_users[] is initial.
*---Lock/unlock users
    update usr02 set uflag = p_uflag
           where bname in r_users
                 .
    if sy-subrc = 0.
      commit work.
*-----Create change documents entries
      perform insert_ush02 tables p_users.
    else.
      rollback work.
    endif.
  endif.

*-Release locks after processing
  dequeue_mass.

*-Log users skipped due to unsufficient privileges if any
  if not num_noauth is initial. log_skipped_noauth. endif.

  perform refresh_list.
endform. "LOCK_UNLOCK_MASS
*-----------------------------------------------------------------------
form upload_phones.
  data:
    fsize type i                               "#EC NEEDED
  , ftype like rlgrap-filetype value 'ASC'
  , fname like rlgrap-filename
*                value '\\computer.domain.com\share\phones.txt'
*                value 'C:\SAPworkdir\phones.txt'
  .
  clear: phone_flg, it_phone[].

  check p_upload = 'X'
    and f_javagui is initial "<- Be sure, that it's not a Java GUI
*   and ( enable_chk1 is initial
*         or sy-uname = sapstar
*         or sy-uname = admin_1
*         or sy-uname = admin_2
*         or sy-uname = admin_3
*         or sy-uname = admin_4
*         or sy-uname = admin_5
*         or sy-uname = admin_6
*         or sy-uname = admin_7
*         or sy-uname = admin_8
*         or sy-uname = admin_9
*         or sy-uname = power_1
*         or sy-uname = power_2
*         or sy-uname = power_3
*         or sy-uname = power_4
*         or sy-uname = power_5
*         or sy-uname = power_6
*         or sy-uname = power_7
*         or sy-uname = power_8
**        or sy-uname = rfc_user
*       )
  .
  if p_phones = space. exit.
                 else. move p_phones to fname. endif.

  call function 'WS_UPLOAD'
       exporting
         filename                = fname
         filetype                = ftype
       importing
         filelength              = fsize
       tables
         data_tab                = it_phone
       exceptions
         conversion_error        = 1
         file_open_error         = 2
         file_read_error         = 3
         invalid_table_width     = 4
         invalid_type            = 5
         no_batch                = 6
         unknown_error           = 7
         gui_refuse_filetransfer = 8
         customer_error          = 9
         .
  case sy-subrc.
    when 0.
      move 'X' to phone_flg.
      sort it_phone by bname.
    when 2.
      app_log_z2_0 '105'.
*----'Can not open file with phones'
      message s105.
    when 3.
      app_log_z2_0 '106'.
*----'Can not read file with phones'
      message s106.
    when others.
*     other error, not yet handled
  endcase.

  if expert = 'X'.
*---Restore eliminated warning on expert mode
    perform warning_on_expert.
  endif.
endform. "UPLOAD_PHONES
*-----------------------------------------------------------------------
form show_documentation.
  if fm_show_doc-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_show_doc-name.
*--'Called function module does not exist in the system &' + &V2&
    message w063 with sy-sysid fm_show_doc-name.
  else. call function fm_show_doc-name. endif.
endform. "SHOW_DOCUMENTATION
*-----------------------------------------------------------------------
form call_selection_screen.
  perform refresh_time_display.
*-Open default tabstrip if it's required
* tb1-activetab = 'UCOM2'.
*  if p_deftab = 'X'.
*    set_fcode 'UCOM2'.
**   if sy-subrc <> 0.
**     clear sy-subrc.
***    set user-command 'UCOM2'.
**   endif.
*  endif.

*-Show selection screen
  call selection-screen 1000 starting at 20 2.
  if sy-subrc = 0.
    perform depend_cpynam.
*---Refresh data
    perform start_of_selection using space.
    if p_return = 'X' and sum_usr < prev_sum.
*-----Jump to first page
      perform jump_to_first_page.
    endif.
  else. perform action_cancelled. endif.
endform. "CALL_SELECTION_SCREEN
*-----------------------------------------------------------------------
form file_exists using value(fname) changing rc like sy-subrc.
*-Look if this path+file already exists on PC
  clear rc.
  call function 'WS_QUERY'
       exporting
         filename =  fname
         query    = 'FE'
       importing
         return   =  rc  "0 - does not exist; 1 - exists
       exceptions
         others   =  2
         .
  if sy-subrc <> 0. rc = 3. endif. "Exception raised during check
endform. "FILE_EXISTS
*-----------------------------------------------------------------------
form execute_object using v_url like smen_buffi-url.
  call function 'NAVIGATION_EXECUTE_OBJECT'
       exporting
         control_instance            =  space
         object_name                 =  space
         reporttype                  = 'OT'
         sap_guid                    =  space
         new_window                  = 'X'
         target_system               =  space
         url                         =  v_url
         bw_active                   =  space
         no_progress_indicator       =  space
         replace_rfc_variables       = 'X'
         check_trusted_system        = 'X'
         do_no_allow_untrusted_start = 'X'
         read_sy_datar               =  space
         .
  app_log_z2_1 '062' v_url.
*-'Last executed object: &1'
  message s062 with v_url.

endform. "EXECUTE_OBJECT
*-----------------------------------------------------------------------
form call_vnc using value(v_terminal). "like uinfo2-terminal.
  data:
    rc    like sy-subrc
  , v_url like smen_buffi-url "value '\\computer.domain.com\share\&.cmd'
  .
*-Check for active ARFC calls
  check_arfc.

  if v_vnc = space.
    app_log_z2_2 '097' loctab key_vnc.
*--'Full path must be set in tab. &1 under key &2'
    message s097 with loctab key_vnc.
    exit.
  else.
    move v_vnc to v_url.
  endif.

  condense v_terminal.
  replace amp with v_terminal into v_url. condense v_url no-gaps.

  move v_terminal to pop_txt. condense pop_txt.
  concatenate 'Do you want to launch VNC for'(921)
               pop_txt
         into  pop_txt
               separated by space
               .
  confirm_step 'Y'
                pop_txt
                v_url
               'Launch VNC'(920)
                .
  case ans.
    when 'J'. perform file_exists using v_url changing rc.
              case rc.
                when 0.
                  app_log_z2_1 '041' v_url.
*----------------'File & not exists'
                  message e041 with v_url.

                when 3.
                  app_log_z2_2 '031' text-220 v_url.
                  message e031 with 'Cannot access'(220) v_url.

                when others. "rc = 1, file exists
                  concatenate 'file:' v_url into v_url.   "#EC NOTEXT
                  perform execute_object using v_url.

              endcase.
  endcase.
  perform simulate_sapgui_update.
endform. "CALL_VNC
*-----------------------------------------------------------------------
form cleanup_spopli.
  cls it_spopli.
  clear: spop5txt1, spop5txt2, spop5txt3, spop5titel. def_radio = 1.
endform. "CLEANUP_SPOPLI
*-----------------------------------------------------------------------
form get_smtp_address using v_mandt     like sy-mandt
                            v_bname     like sy-uname
                   changing v_smtp_addr like adr6-smtp_addr
                            .
  if fm_smtp_adr-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_smtp_adr-name.
*--'Called function module does not exist in the system &' + &V2&
    message s063 with sy-sysid fm_smtp_adr-name.
  else.
    call function fm_smtp_adr-name
         exporting
           mandt          = v_mandt
           bname          = v_bname
         importing
           smtp_addr      = v_smtp_addr
         exceptions
           data_not_found = 1
           .
    if sy-subrc <> 0. clear v_smtp_addr. endif.
  endif.
endform. "GET_SMTP_ADDRESS
*-----------------------------------------------------------------------
form mail_to.
  data:
    v_man_bname(16)
  , s_sapmail like spopli-varoption
  , s_extmail like spopli-varoption
  .
  get_and_check_sel_bname.

*-Check for active ARFC calls
  check_arfc.

  perform cleanup_spopli.

  concatenate p_mandt sel_bname into v_man_bname separated by space.
  condense v_man_bname.

  spop5titel = 'Send E-mail to &'(866).
  replace amp with v_man_bname into spop5titel. condense spop5titel.

  s_extmail = '@E2@ External program &'(869).
  perform get_smtp_address using p_mandt sel_bname
                        changing v_smtp_addr
                                 .
  if v_smtp_addr is initial.
    move '<E-mail unknown>'(870) to s_email.
  else.
    condense v_smtp_addr.
    concatenate '<' v_smtp_addr '>'
           into  s_email.
  endif.
  condense s_email.

  replace amp with s_email into s_extmail. condense s_extmail.

  if p_mandt = sy-mandt.
    def_radio = 1.
    s_sapmail = '@DZ@ SAPOffice -> &'(868).
    replace amp with v_man_bname into s_sapmail. condense s_sapmail.

    app_spopli 'X' s_sapmail ' '.
    app_spopli 'X' s_extmail ' '.
  else.
    def_radio = 2.
    s_sapmail = '@00@ SAPOffice cannot be used for client &'(867).
    replace amp with p_mandt into s_sapmail. condense s_sapmail.

    app_spopli ' ' s_sapmail 'X'.
    app_spopli 'X' s_extmail ' '.
  endif.

  call function 'POPUP_TO_DECIDE_LIST'
       exporting
         cursorline         =  def_radio
         mark_flag          = ' '
         mark_max           =   1
         start_col          =  25
         start_row          =   6
         textline1          = 'Please choose a mailing program'(863)
         textline2          = 'that you want to be used here'(864)
         textline3          =  space
         titel              =  spop5titel
*        display_only       = ' '
       importing
         answer             =  ans
       tables
         t_spopli           =  it_spopli
       exceptions
         not_enough_answers =   1
         too_much_answers   =   2
         too_much_marks     =   3
         .
  if sy-subrc <> 0.
    app_log_z2_0 '090'.
*--'Internal error. This function is not possible.'
    message e090.
  elseif ans <> 'A'.
    case ans.
      when '1'. perform int_mail_to using p_mandt sel_bname.
      when '2'. perform ext_mail_to using p_mandt sel_bname.
    endcase.
  else. perform action_cancelled. endif.
endform. "MAIL_TO
*-----------------------------------------------------------------------
form int_mail_to using v_mandt like sy-mandt v_bname like sy-uname.
  data:
    st1(70)
  , st2             like st1
  , name_first      like adrp-name_first
  , name_last       like adrp-name_last
  , buf_line        like mcmailobj-objline
  , err_msg(40)

  , begin of tsd_mailobject_cont occurs 1.
      include       structure mcmailobj.
  data:
    end   of tsd_mailobject_cont
  , tsd_mail_title  like sood1-objnam
  , tsd_mail_objdes like sood1-objdes
  .
define app_body.
  clear tsd_mailobject_cont.
  tsd_mailobject_cont-objnr    = '1'.
  tsd_mailobject_cont-objlevel = '0'.
  tsd_mailobject_cont-objtype  = 'RAW'.
  tsd_mailobject_cont-objnam   = '1'.
  tsd_mailobject_cont-objdes   = '1'.
  tsd_mailobject_cont-objline  = &1.
  append tsd_mailobject_cont.
end-of-definition. "APP_BODY

define get_name.
*-First, read an internal table (faster!)
  read table it with key mandt = &1 bname = &2.
*-if entry not found, read data from DB
  if sy-subrc <> 0.
    perform get_user_name
                    using &1 &2
                 changing &3 &4
                          .
  else. r_names &3 &4. endif.
end-of-definition. "GET_NAME

*-Sender
* get_name sy-mandt sy-uname my_name_first my_name_last.
  if my_name_first is initial and my_name_last is initial.
    move sy-uname to buf_line.
  else.
    concatenate my_name_last my_name_first
           into buf_line
                separated by space
                .
  endif.

*-Recipient
  get_name v_mandt v_bname name_first name_last.
  if name_first = space. move v_bname to name_first. endif.

  concatenate: 'Message from user'(861) sy-uname
         into   st1
                separated by space
            ,   name_first '!'
         into   st2
                .
  tsd_mail_title = tsd_mail_objdes = st1.

  cls tsd_mailobject_cont.

  app_body  st2.
  app_body  space.
  app_body  space.
  app_body 'Best Regards,'(862).
  app_body  buf_line.

  call function 'MC_SEND_MAIL'
       exporting
         ms_mail_sendmode          = 'O' "Online
         ms_mail_title             =  tsd_mail_title
         ms_mail_description       =  tsd_mail_objdes
         ms_mail_receiver          =  v_bname
         ms_mail_express           = 'X'
*        ms_mail_dliname           =
*        ms_mail_langu             =  sy-langu
*        ms_mail_funkobj_typ       =
*        ms_mail_funkobj_name      =
*      importing
*        ms_ok_code                =
       tables
         ms_mail_cont              =  tsd_mailobject_cont
*        ms_mail_funkobj_parm      =
*        ms_mail_setget_parm       =
*        ms_mail_receivers         =
       exceptions
         send_error                = 1
         canceled                  = 2
         no_title                  = 3
         no_description            = 4
         no_receiver_or_dli        = 5
         invalid_sendmode          = 6
         no_content                = 7
         invalid_functional_params = 8
         others                    = 9
         .
  case sy-subrc.
    when 0.      "rr_msg = 'Message sent'.
    when 1.      err_msg = 'Send error'(871).
    when 2.      err_msg = 'Sending cancelled'(872).
*   when 3.      err_msg = 'No title'.
*   when 4.      err_msg = 'No description'.
*   when 5.      err_msg = 'No receiver or DLI'.
*   when 6.      err_msg = 'Invalid sendmode'.
*   when 7.      err_msg = 'No content'.
*   when 8.      err_msg = 'Invalid functional params'.
    when others. err_msg = 'Unknown error encountered'(873).
  endcase.

  if sy-subrc <> 0.
    app_log_z2_1 '030' err_msg.
    message s030 with err_msg.
  endif.
endform. "INT_MAIL_TO
*-----------------------------------------------------------------------
form ext_mail_to using v_mandt like sy-mandt v_bname like sy-uname.
  constants v_prot(7) value 'mailto:'.
  data:
    st1(70)
  , st2        like st1
  , name_first like adrp-name_first
  , name_last  like adrp-name_last
  , smtp_addr  like adr6-smtp_addr
  , v_url      like smen_buffi-url
*     value 'mailto:abc@def.com?Subject=Info from SAP user&Body=Hello!'
  .
  if v_bname is initial or fm_smtp_adr-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_smtp_adr-name.
*--'Called function module does not exist in the system &' + &V2&
    message w063 with sy-sysid fm_smtp_adr-name.
    exit.
  else.
    call function fm_smtp_adr-name
         exporting
           mandt          = v_mandt
           bname          = v_bname
         importing
           smtp_addr      = smtp_addr
         exceptions
           data_not_found = 1
           .
    if sy-subrc <> 0.
      app_log_z2_2 '061' v_bname v_mandt.
*----'E-mail for user &1 (&2) not found'
      message e061 with v_bname v_mandt.
    else.
*     condense v_url no-gaps.

      if p_nofill is initial.
*-------First, read an internal table (faster!)
        read table it with key mandt = v_mandt bname = v_bname.
*-------if entry not found, read data from DB
        if sy-subrc <> 0.
          perform get_user_name
                          using v_mandt    v_bname
                       changing name_first name_last
                                .
        else. r_names name_first name_last. endif.

        if name_first = space. move v_bname to name_first. endif.

        concatenate:
                     '?Subject=Info from SAP R/3 user'(778) sy-uname
               into   st1
                      separated by space

                   , '&Body=Hello'(779) name_first
               into   st2
                      separated by space

                   ,  v_prot smtp_addr st1 st2 '!'        "#EC NOTEXT
               into   v_url
                      .
      else. concatenate v_prot smtp_addr into v_url. endif.
      condense v_url.
    endif.
  endif.
  perform execute_object using v_url.

* perform simulate_sapgui_update.
endform. "EXT_MAIL_TO
*-----------------------------------------------------------------------
form toggle_wide.
  if p_match is initial.
    app_log_z2_0 '107'.
*--'At first, switch filter ON'
    message s107.
  else. sessions_toggle_flag p_wide. endif.
endform. "TOGGLE_WIDE
*-----------------------------------------------------------------------
define mac_goto_remote.
* read current line field value &1.
  if   ( &1 is initial )
*   or ( sy-subrc <> 0 )
       .
    navigation_impossible.
  else.
    perform goto_server using &1.
*   exit.
  endif.
end-of-definition. "MAC_GOTO_REMOTE
*-----------------------------------------------------------------------
form line_selection_u.
  check sy-pfkey = 'USER'.
  clear nav. get cursor field nav.

  abscol = sy-cucol + sy-staco - 1. clear ui2.

  define run_tcode.
    read current line field value ui2-tcode.
    read current line field value ttext.
    if ( sy-subrc = 0 ) and not ( ui2-tcode is initial ).
      perform call_user_transaction using ui2-tcode ttext.
    endif.
  end-of-definition. "RUN_TCODE

  define run_vnc.
    read current line field value ui2-terminal.
    if ( sy-subrc = 0 ) and not ( ui2-terminal is initial ).
      perform call_vnc using ui2-terminal.
    endif.
  end-of-definition. "RUN_VNC

  case nav.
*---Switch Filter ON/OFF
    when 'FILT_ICON'.
      perform toggle_flag changing p_usfilt.
*     perform simulate_sapgui_update_ex.
      perform smart_show_long_usr_info.

*---Show/Hide Additional Buttons for user-oriented tasks
    when 'UBTN_SYMB'
*     or 'F_USERBTN'
          .
      perform toggle_flag changing f_userbtn.
*     perform simulate_sapgui_update_ex.
      perform smart_show_long_usr_info.

*---Switch 'Transactions in New Mode' ON/OFF
    when 'P_NEWMOD'.
      perform toggle_flag changing p_newmod.
*     perform simulate_sapgui_update_ex.
      perform smart_show_long_usr_info.

*---Show Last Registered Auth. Failure
    when 'SU53_ICON'.
      set_fcode 'FAIL'.

*---Show Auth. Object
    when 'USR07-OBJCT'.
      set_fcode 'OBJT'.

*---Find Auth. Object usage in User Master Records
    when 'WUSR_ICON'.
      set_fcode 'OUSR'.

*---Find Auth. Object usage in Roles (Activity Groups)
    when 'WAGR_ICON'.
      set_fcode 'OAGR'.

*---Delete obsolete entry from table USR07
    when 'DELE_ICON'.
      perform delete_entry_from_usr07 using p_mandt sel_bname.

*---Fill request to change user's authorizations
    when 'FORM_ICON'.
      set_fcode 'REQU'.

*---Show history of registered auth. failures
    when 'HIST_ICON'.
      set_fcode 'FAIH'.

*---Switch Memory Details ON/OFF
    when 'MEMD_SYMB'.
      perform toggle_flag changing p_detail.
*     perform simulate_sapgui_update_ex.
      perform smart_show_long_usr_info.

*---Go to System Trace
    when 'ST01_SYMB'
*     or 'ST01_ICON'
          .
      perform call_transaction using 'ST01'.

*---Maintain user
    when 'USR41-BNAME'
*     or 'USR41-MANDT'
          .
      perform call_su01_ex using usr41-mandt usr41-bname.

*---Show spool
    when 'SPOO_ICON'.
*     clear: usr41-mandt, usr41-bname.
*     read current line field value usr41-mandt.
*     read current line field value usr41-bname.
      if   ( usr41-mandt is initial )
        or ( usr41-mandt is initial )
*       or ( sy-subrc <> 0 )
        .
        navigation_impossible.
      else. perform show_spool using usr41-mandt usr41-bname. endif.

*---Display user details
    when 'UADR_ICON'.
      show_details usr41-bname usr41-mandt.

*---Display user details
    when 'UADR_HEAD'.
      show_details sel_bname   p_mandt.

*---Display roles assigned to user
    when 'UAGR_ICON'.
      perform show_roles_ex       using usr41-mandt usr41-bname f_ar.

*---Display roles assigned to user
    when 'UAGR_HEAD'.
      perform show_roles_ex       using p_mandt     sel_bname   f_ar.

*---Display authorization tree
    when 'AUTH_ICON'.
      perform display_user_auths  using             usr41-bname.

*---Display authorization tree
    when 'AUTH_HEAD'.
*     if p_mandt = sy-mandt.
      notify_about_client.
      perform display_user_auths  using             sel_bname.
*     endif.

*---Display allowed transactions
    when 'U010_ICON'.
      perform list_allowed_tcodes using usr41-mandt usr41-bname.

*---Display allowed transactions
    when 'U010_HEAD'.
      perform list_allowed_tcodes using p_mandt     sel_bname.

*---Display change documents
    when 'U100_ICON'.
      perform go_change_documents using usr41-mandt usr41-bname.

*---Display change documents
    when 'U100_HEAD'.
      perform go_change_documents using p_mandt     sel_bname.

*---Send POPUP message
    when 'SEND_ICON'.
      perform send_popup_to_user  using usr41-mandt usr41-bname.

*---Run VNC
    when 'USR41-TERMINAL'.
*     read current line field value usr41-terminal.
      split usr41-terminal at '-'
       into usr41-terminal usr41-terminal
            .
      perform call_vnc using usr41-terminal.

*---Reserved
*   when 'USR41-TERMID'.
*     ...

*---Go to remote server
    when 'USR41-SERVER'.
      mac_goto_remote usr41-server.

*---Go to remote server
    when 'W_ULIST-APSERVER'.
*-----for SAP R/3 Release 4.6C
      mac_goto_remote w_ulist-apserver.
*-----for SAP R/3 Enterprise (4.7)
*     data converted_dest like msxxlist-name.
*     move w_ulist-apserver to converted_dest.
*     mac_goto_remote converted_dest.

*---Read TCODE and View ABAP source code
    when 'ABAP_ICON'.
      read current line field value ui2-tcode.
      perform view_source using ui2-tcode.

*---Call transaction
    when 'TRAN_ICON'.
      run_tcode.

*---Navigate to transaction
    when 'TTEXT'.
      read current line field value ui2-tcode.
      if ( sy-subrc = 0 ) and not ( ui2-tcode is initial ).
        move ui2-tcode to v_obj_name.
        navigate 'TRAN' v_obj_name.
      endif.

*---Run VNC
    when 'MONI_ICON'.
      run_vnc.

*---Run VNC
    when 'W_ULIST-TERM'.
      if not w_ulist-term is initial.
        perform call_vnc using w_ulist-term.
      endif.

*---Switch Autorefresh ON/OFF
*   when 'AREF_SYMB'.
    when 'AREF_ICON'.
      perform toggle_aref.
      perform smart_show_long_usr_info.

*---Increase autorefresh time interval
    when 'ARUP_SYMB'.
      check arfc_secs < arfc_max.
      perform arfc_up.
      perform smart_show_long_usr_info.

*---Decrease autorefresh time interval
    when 'ARDN_SYMB'.
      check arfc_secs > arfc_min.
      perform arfc_down.
      perform smart_show_long_usr_info.

*---All other cases
    when others.
      if     abscol between 22 and 44.
*-------Call transaction
        run_tcode.
*     elseif abscol between 46 and 81.
**------Navigate to transaction
*       read current line field value ui2-tcode.
*       if ( sy-subrc = 0 ) and not ( ui2-tcode is initial ).
*         move ui2-tcode to v_obj_name.
*         navigate 'TRAN' v_obj_name.
*       endif.
      elseif abscol between 83 and 105.
*-------Run VNC
        run_vnc.
      endif.
  endcase.
endform. "LINE_SELECTION_U
*-----------------------------------------------------------------------
form line_selection_s.
  data:
    cur_x      like sy-cucol
  , new_cursor like sy-staro
  , listindex  like sy-lsind
  , err_txt(25)
  .
  check sy-pfkey = 'SESS'.
  clear nav. get cursor field nav.

  case nav.
*---Mark user
    when 'IT41S-MARK'.
      perform toggle_user_s.

*---Show user activity
    when 'IT41S-MANDT'
      or 'IT41S-BNAME'
      or 'IT41S-NAME_LAST'
      or 'IT41S-NAME_FIRST'
      or 'IT41S-TERMINAL'
      or 'IT41S-DIFF'
      or 'IT41S-TIME'
*     or 'IT41S-SERVER'
      or 'IT41S-TCODE'
      or 'IT41S-PAGE'
      or 'IT41S-ROLL'
      or 'IT41S-MEMSUM'
      or 'IT41S-PRIVSUM'
          .
      perform show_user_activity.

*---Go to remote server
    when 'IT41S-SERVER'.
      perform goto_remote_server.

*---Select/Deselect all users
    when 'F_SELE_S'.
      perform toggle_flag changing f_sele_s.
      if f_sele_s = 'X'.
        perform cmd_select_all_s.
      else.
        perform cmd_select_none_s.
      endif.

*---Show/Hide RFC connections, lost GUI sessions, plugins...
    when 'EXTR_SYMB'.
      perform toggle_flag changing f_extr.
      perform print_table_s.
      perform jump_to_last_page.

*---Set selected line first in the list
*   when 'ERFC_SYMB'.
*     lilli = sy-lilli.
*     lirow = sy-staro.
*     call function 'LIST_SCROLL_LINE_TOPMOST'
*          exporting
*            list_line   = lilli
*          importing
*            scroll_line = lirow
*          exceptions
*            others      = 4
*            .
*     if sy-subrc = 0.
**      ...
*     endif.

*---Internal use: Show All Entries/Extra only
*   when 'F_TH_ALL'.
*     if not expert is initial.
*       sessions_toggle_flag f_th_all.
*     endif.

*---Jump to previous fragment
    when 'FRUP_SYMB'.
      set_fcode 'PP-'.

*---Jump to next fragment
    when 'FRDN_SYMB'.
      set_fcode 'PP+'.

*---Scroll list to the beginning of extra sessions output
    when 'JUMP_SYMB'.
      listindex  = sy-lsind - 1.
      new_cursor = extr_ln - 3.

      if p_match eq 'X'. subtract 1 from new_cursor. endif.
      if new_cursor < 0.       new_cursor = 1.       endif.

      set cursor line extr_ln.

      call function 'LIST_SCROLL_FOLLOWING_CURSOR'
           exporting
             list_index            = listindex
             cursor_line           = new_cursor
             cursor_offset         = 2
           exceptions
             list_index_invalid    = 1
             list_line_not_found   = 2
             no_list_active        = 3
             window_too_small      = 4
             cursor_offset_invalid = 5
             .
      case sy-subrc.
        when 0.      set cursor field 'EXTR_SYMB'.
        when 1.      err_txt = 'LIST_INDEX_INVALID   '. "#EC NOTEXT
        when 2.      err_txt = 'LIST_LINE_NOT_FOUND  '. "#EC NOTEXT
        when 3.      err_txt = 'NO_LIST_ACTIVE       '. "#EC NOTEXT
        when 4.      err_txt = 'WINDOW_TOO_SMALL     '. "#EC NOTEXT
        when 5.      err_txt = 'CURSOR_OFFSET_INVALID'. "#EC NOTEXT
        when others. move sy-subrc to err_txt.
      endcase.
      if sy-subrc <> 0.
        app_log_z2_2 '031' text-142 err_txt.
        message e031 with 'Cannot scroll list, rc ='(142) err_txt.
      endif.

*---Show user activity
    when 'IT_EXTRA-TID'
      or 'IT_EXTRA-MANDT'
      or 'IT_EXTRA-BNAME'
      or 'IT_EXTRA-TCODE'
      or 'IT_EXTRA-TERM'
      or 'IT_EXTRA-ZEIT'
      or 'IT_EXTRA-IP_ADDR'
      or 'IT_EXTRA-ICONID'
      or 'IT_EXTRA-TYPE_TXT'
      or 'IT_EXTRA-STAT_TXT'
      or 'IT_EXTRA-GUIVERSION'
          .
      perform show_user_activity_rfc.

*---Toggle flag P_MATCH
    when 'NOTE_SYMB'.
      sessions_toggle_flag p_match.

*---Export data to Excel
    when 'XCEL_ICON'.
      perform export_to_excel_sess.

*---Show RFC connections, lost GUI sessions, plugins...
*   when 'EXTR_SYMB'.
*     perform fill_it_extra.

*---Toggle flag P_WIDE
    when 'WIDE_ICON'.
      sessions_toggle_flag p_wide.

*---Client: new value has been entered
    when 'CLIS_ICON'.
      perform process_input_s.

*---Switch Autorefresh ON/OFF
*   when 'AREF_SYMB'.
    when 'AREF_ICON'.
      perform toggle_aref.
      perform refresh_list_s.

*---Increase autorefresh time interval
    when 'ARUP_SYMB'.
      check arfc_secs < arfc_max.
      perform arfc_up.
      perform refresh_list_s.

*---Decrease autorefresh time interval
    when 'ARDN_SYMB'.
      check arfc_secs > arfc_min.
      perform arfc_down.
      perform refresh_list_s.

*---List of SAP Systems
    when 'SM51_ICON'.
      perform call_transaction using 'SM51'.

*---Systemwide Work Process Overview
    when 'SM66_ICON'.
      perform call_transaction using 'SM66'.

*---Reserved
    when 'MANDT_F'.
*     ...

*---Empty field
    when space.
      cur_x = sy-staco + sy-cucol - 1.
      if sy-curow gt head_bo_s and     "If relative line > HEAD_RO_S and
         sy-lilli le last_ln_s and     "  absolute line inside of list
         cur_x between 1 and 90.
        perform show_user_activity.
      endif.

*---All other cases
    when others.

  endcase.
endform. "LINE_SELECTION_S
*-----------------------------------------------------------------------
form get_program_by_tcode using v_tcode like sy-tcode
                       changing v_repid like sy-repid
                                .
  select single pgmna
                into v_repid
                from tstc where tcode = v_tcode
                     .
  if sy-subrc <> 0. clear v_repid. endif.
endform. "GET_PROGRAM_BY_TCODE
*-----------------------------------------------------------------------
form view_source using v_tcode like sy-tcode.
  data v_repid like sy-repid.

  perform get_program_by_tcode using v_tcode changing v_repid.
  perform call_editor          using                  v_repid.
  perform simulate_sapgui_update.
endform. "VIEW_SOURCE
*-----------------------------------------------------------------------
form call_editor using v_repid like sy-repid.
  data auth_obj like tobj-objct value 'S_DEVELOP'.

*-Check for active ARFC calls
  check_arfc.

  authority-check object auth_obj
    id 'DEVCLASS' dummy
    id 'OBJTYPE'  field 'PROG'
    id 'OBJNAME'  field  v_repid
    id 'P_GROUP'  dummy
    id 'ACTVT'    field '03'
    .
  if sy-subrc <> 0.
*--'No authorization for this action'
*   message i005(1x).
*   app_log_00_1 '149' auth_obj.
*--'You haven't authorization for object &'
*   message i149(00) with auth_obj.
    app_log 'DG' '820' auth_obj space space space.
*--'No authorization to display data for object &1'
    message i820(dg) with auth_obj.
  else.
    call function 'EDITOR_PROGRAM'
         exporting
           display     = 'X'
*          line        =  1
*          message     = 'Display mode active'
           program     =  v_repid
         exceptions
           application =  1
           .
    if sy-subrc <> 0.
*-----REM because this error handled in called function
*     app_log_ds_1 v_repid.
**---'Program & does not exist'
*     message e017(ds) with v_repid.
      exit.
    endif.
  endif.
endform. "CALL_EDITOR
*-----------------------------------------------------------------------
form show_phones_file_content.
  if phone_flg = 'X'.
    editor-call for it_phone title p_phones display-mode.
  else.
    app_log 'G00' '169' space space space space.
*--'No file with structure data loaded'
    message s169(g00).
  endif.
endform. "SHOW_PHONES_FILE_CONTENT
*-----------------------------------------------------------------------
form get_location using value(key) changing v_path.
  clear v_path. condense v_path.

  is_tab_exists loctab.
  if sy-subrc <> 0. exit. endif.

  select single path into v_path
                     from (loctab)
                     where name = key
                           .
  if sy-subrc <> 0. exit. endif.
  condense v_path.
endform. "GET_LOCATION
*-----------------------------------------------------------------------
form check_hist_tab.
*-Does history table exist?
  is_tab_exists histtab.
  if sy-subrc <> 0. f_histtab = ' '.
              else. f_histtab = 'X'. endif.
endform. "CHECK_HIST_TAB
*-----------------------------------------------------------------------
form submit_report using value(v_repid). " like sy-repid.
*-Check program existence and type
  is_executable v_repid.

  perform issue_run_message using v_repid 'X'.
  submit (v_repid)
*    via selection-screen
     and return
         .
  perform simulate_sapgui_update.
endform. "SUBMIT_REPORT
*-----------------------------------------------------------------------
form get_program_title using v_repid like sy-repid
                             v_langu like sy-langu
                    changing v_title like trdirt-text
                             .
  v_title = '[ description in language & not found ]'(086).
  replace amp with v_langu into v_title. condense v_title.

  select single text into v_title
                     from trdirt
                     where name  = v_repid
                       and sprsl = v_langu
                           .
endform. "GET_PROGRAM_TITLE
*-----------------------------------------------------------------------
form run_or_view_program using value(v_repid). " like sy-repid.
  data:
    v_text like trdirt-text
  , v_rep  like raldb-report
  , v_title(40)
  , v_ans(3)
  .
*-Check program existence and type
  is_executable v_repid.

  concatenate 'Start program'(303)
               v_repid
         into  v_title
               separated by space
               .
  condense v_title.

  perform get_program_title using v_repid langu changing v_text.

*------<report name> + <report description>
  concatenate v_repid v_text
         into pop_txt
              separated by ' - '
              .
  clear v_ans. v_rep = v_repid. "Safety type conversion
  call function 'RS_SELSCREEN_EXISTS'
       exporting
         report            = v_rep
*        accept_non_report =
       importing
         answer            = v_ans
       exceptions
         no_report         = 1
         program_incorrect = 2
         program_not_found = 3
         others            = 4
         .
  if sy-subrc = 0 and v_ans = 'YES'.
    confirm_step 'Y'
                 'Do you want to run the program'(136)
                  pop_txt
                  v_title
                  .
    if ans = 'J'.
      submit (v_repid)
         via selection-screen
         and return
             .
      perform simulate_sapgui_update.
    else. perform action_cancelled. endif.
  else.
    clear ans.
    call function 'POPUP_TO_DECIDE'
         exporting
           defaultoption     =  2
           textline1         =  pop_txt
*-'The program hasn''t a selection-screen, so that may not be safe!!!'
           textline2         =  text-874
*-'Run the program (NOT SAFE) or display its source code (RECOMMENDED)?'
           textline3         =  text-877
           text_option1      = 'Run'(875)
           text_option2      = 'Display'(876)
           icon_text_option1 = 'ICON_EXECUTE_OBJECT'
           icon_text_option2 = 'ICON_DISPLAY'
           titel             =  v_title
           start_column      =  25
           start_row         =   6
           cancel_display    = 'X'
         importing
           answer            =  ans
           .
    case ans.
      when '1'. perform issue_run_message using v_repid 'X'.
                submit (v_repid)
*                  via selection-screen
                   and return
                       .
                perform simulate_sapgui_update.
      when '2'. perform call_editor using v_repid.
*     when 'A'.
      when others. perform action_cancelled.
    endcase.
  endif.
endform. "RUN_OR_VIEW_PROGRAM
*-----------------------------------------------------------------------
form list_allowed_tcodes using v_mandt like sy-mandt
                               v_bname like sy-uname
                               .
  data v_list_tcd like sy-repid value 'RSUSR010'.

*-Check for active ARFC calls
  check_arfc.

*-Check program existence and type
  is_executable v_list_tcd.

  check v_mandt = sy-mandt.

* set parameter id 'XUS' field v_bname.
  perform confirm_program_run using v_list_tcd.
  case ans.
    when 'J'.
      perform issue_run_message using v_list_tcd 'X'.
      submit (v_list_tcd)
        with user = v_bname
         and return
             .
      perform simulate_sapgui_update.
    when others.
      perform action_cancelled.
  endcase.
endform. "LIST_ALLOWED_TCODES
*-----------------------------------------------------------------------
form go_change_documents using v_mandt like sy-mandt
                               v_bname like sy-uname
                               .
  data v_change_doc like sy-repid value 'RSUSR100'.

*-Check for active ARFC calls
  check_arfc.

*-Check program existence and type
  is_executable v_change_doc.

  check v_mandt = sy-mandt.
* set parameter id 'XUS' field v_bname.
* perform confirm_program_run using v_change_doc.
* case ans.
*   when 'J'.
*     perform issue_run_message using v_change_doc 'X'.
      submit (v_change_doc)
        with user = v_bname
         via selection-screen
         and return
             .
      perform simulate_sapgui_update.
*   when others.
*     perform action_cancelled.
* endcase.
endform. "GO_CHANGE_DOCUMENTS
*-----------------------------------------------------------------------
form call_browser using value(v_url).
  check v_url ne space.
*-Execute URL
  call function 'WS_EXECUTE'
       exporting
         document  = 'X'
*        inform    = 'X'            " // synchronous
         program   =  v_url
         .
  if sy-subrc <> 0.
    app_log_z2_008 sy-subrc.
*--'Error: &1'
    message i008 with sy-subrc.
    exit.
  endif.
endform. "CALL_BROWSER
*-----------------------------------------------------------------------
form other_okcode.
  data:
    v_repid like sy-repid
  , v_url   type path
  .
  if sy-ucomm is initial. exit. endif.

*-Check for active ARFC calls
  check_arfc.

  define get_obj_name.
    move sy-ucomm   to v_obj_name. shift v_obj_name left.
    move v_obj_name to v_repid.
  end-of-definition. "GET_OBJ_NAME

  if sy-ucomm(7) = 'HTTP://'  or                            "#EC NOTEXT
     sy-ucomm(7) = 'FTP://'   or                            "#EC NOTEXT
     sy-ucomm(8) = 'FILE:///' or                            "#EC NOTEXT
     sy-ucomm(2) = '\\'                                     "#EC NOTEXT
     .
*----Try to start a link in standard browser
     move sy-ucomm to v_url.
     perform call_browser using v_url.
  else.
    case sy-ucomm(1).
*-----Do nothing
      when '/'.
*-----Run program
      when '~'.    get_obj_name.
                   perform run_or_view_program using v_repid.
*-----View program source
      when '^'.    get_obj_name.
                   navigate 'PROG' v_obj_name.
*                  perform call_editor using v_repid.

*-----View transaction code definition
      when '\'.    get_obj_name.
                   navigate 'TRAN' v_obj_name.
*-----Call transaction
      when others. perform call_transaction using sy-ucomm.
    endcase.
  endif.
endform. "OTHER_OKCODE
*-----------------------------------------------------------------------
form reset_selected_users.
  data rc like sy-subrc.

*-Check for active ARFC calls
  check_arfc.

  if fm_reset_pw-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_reset_pw-name.
*--'Called function module does not exist in the system &' + &V2&
    message w063 with sy-sysid fm_reset_pw-name.
  elseif p_mandt <> sy-mandt.
    app_log_z2_0 '064'.
*--'This function is only allowed for a logon client'
    message w064.
  else.
    check_mark_exists.
    if sy-subrc = 0.
      if expert is initial.
        app_log_z2_1 '030' text-226.
        message w030 with
          'Mass password reset is only allowed in EXPERT mode'(226).
      else.
        confirm_step 'N'
                     'Do you want to reset password'(780)
                     'for ALL selected users? ATTENTION!!!'(227)
                     'Reset password'(782)
                      .
        if ans = 'J'.
          loop at it assigning <fs> where mark = 'X'.
            call function fm_reset_pw-name
                 exporting
                   bname            =  <fs>-bname
                   auto_unlock      = 'X'
                 importing
                   rc               =  rc
                 exceptions
                   user_dont_exists =  1
                   unlock_failed    =  2
                   .
*-----------Just a template. Need to be improved :)
            if sy-subrc <> 0.
              app_log_z2_008 sy-subrc.
*------------'Error: &1'
              message w008 with sy-subrc.
            elseif   rc <> 0.
              app_log_z2_008 rc.
*------------'Error: &1'
              message w008 with rc.
            endif.
          endloop.
        else.
          perform action_cancelled.
          exit.
        endif.
      endif.
    else.
      get_and_check_sel_bname.

*----'Do you want to reset password for' + <username> + '?'
      concatenate text-781 sel_bname '?'
             into pop_txt
                  separated by space
                  .
      confirm_step 'N'
                   'Do you want to reset password'(780)
                    pop_txt
                   'Reset password'(782)
                    .
      if ans <> 'J'. exit. endif.

      call function fm_reset_pw-name
           exporting
             bname            =  sel_bname
             auto_unlock      = 'X'
           importing
             rc               =  rc
           exceptions
             user_dont_exists =  1
             unlock_failed    =  2
             .
*-----Just a template. Need to be improved :)
      if sy-subrc <> 0.
        app_log_z2_008 sy-subrc.
*------'Error: &1'
        message w008 with sy-subrc.
      elseif   rc <> 0.
        app_log_z2_008 rc.
*------'Error: &1'
        message w008 with rc.
      endif.
    endif.
    perform simulate_sapgui_update.
  endif.
endform. "RESET_SELECTED_USERS
*-----------------------------------------------------------------------
*form reset_password using bname like usr02-bname.
*  data rc like sy-subrc.
*
**-Check for active ARFC calls
*  check_arfc.
*
*  if fm_reset_pw-exists is initial.
*    app_log_z2_2 '063' sy-sysid fm_reset_pw-name.
**--'Called function module does not exist in the system &' + &V2&
*    message w063 with sy-sysid fm_reset_pw-name.
*  elseif p_mandt <> sy-mandt.
*    app_log_z2_0 '064'.
**--'This function is only allowed for a logon client'
*    message w064.
*  else.
**--'Do you want to reset password for' + <username> + '?'
*    concatenate text-781 bname '?' into pop_txt separated by space.
*    confirm_step 'N'
*                 'Do you want to reset password'(780)
*                  pop_txt
*                 'Reset password'(782)
*                  .
*    if ans <> 'J'. exit. endif.
*
*    call function fm_reset_pw-name
*         exporting
*           bname            =  bname
*           auto_unlock      = 'X'
*         importing
*           rc               =  rc
*         exceptions
*           user_dont_exists =  1
*           unlock_failed    =  2
*           .
**---Just a template. Need to be improved :)
*    if sy-subrc <> 0.
*      app_log_z2_008 sy-subrc.
**----'Error: &1'
*      message w008 with sy-subrc.
*    elseif   rc <> 0.
*      app_log_z2_008 rc.
**----'Error: &1'
*      message w008 with rc.
*    else. perform simulate_sapgui_update. endif.
*  endif.
*endform. "RESET_PASSWORD
*-----------------------------------------------------------------------
* Original Source see in RSM04000_ALV
form build_mem_list.
  refresh usr_btabl.

  call 'ThUsrInfo'
    id 'OPCODE' field opcode_long_blk_info
    id 'TAB'    field usr_btabl-*sys*
    .
  sort usr_btabl by mandt bname.
endform. "BUILD_MEM_LIST
*-----------------------------------------------------------------------
form export_to_clipboard tables data_tab using value(f_free).
  call function 'CLPB_EXPORT'
       tables
         data_tab   = data_tab
       exceptions
         clpb_error = 1
         .
  if sy-subrc <> 0.
    app_log 'ED' '829' space space space space.
*--'Error when copying to clipboard'
    message e829(ed).
  else.
    app_log 'ED' '814' space space space space.
*--'The block was copied to the buffer'
    message s814(ed).
*---Purge data if requested
    if f_free = 'X'. free data_tab. endif.
  endif.
endform. "EXPORT_TO_CLIPBOARD
*-----------------------------------------------------------------------
form export_to_clipboard_ownmsg tables data_tab
                          using value(f_free)
                                value(v_text)
                                .
  data l_text like sy-msgv1.

  call function 'CLPB_EXPORT'
       tables
         data_tab   = data_tab
       exceptions
         clpb_error = 1
         .
  if sy-subrc <> 0.
    app_log 'ED' '829' space space space space.
*--'Error when copying to clipboard'
    message e829(ed).
  else.
    if v_text is initial.
      app_log_z2_1 '030' text-393.
      message s030 with 'Empty value was copied to the buffer'(393).
    else.
      move v_text to l_text.
      app_log_z2_2 '031' l_text text-394.
      message s031 with l_text 'was copied to the buffer'(394).
    endif.
*---Purge data if requested
    if f_free = 'X'. free data_tab. endif.
  endif.
endform. "EXPORT_TO_CLIPBOARD_OWNMSG
*-----------------------------------------------------------------------
form export_to_clipboard_main.
  check_mark_exists.
  if sy-subrc = 0.
    cls usrlist.
    loop at it assigning <fs> where mark = 'X'.
      usrlist-bname = <fs>-bname. append usrlist.
    endloop.
    perform export_to_clipboard tables usrlist using 'X'.
  else.
    app_log 'L3' '633' space space space space.
*--'Select at least one line'
    message s456(sd).
*   message s633(l3). "Message Class L3 not present in NW2004s
  endif.
endform. "EXPORT_TO_CLIPBOARD_MAIN
*-----------------------------------------------------------------------
form export_to_clipboard_sess.
  read table it41s with key mark = 'X'.
  if sy-subrc = 0.
    cls usrlist.
    loop at it41s assigning <fs2> where mark = 'X'.
      usrlist-bname = <fs2>-bname. append usrlist.
    endloop.
    perform export_to_clipboard tables usrlist using 'X'.
  else.
    app_log 'L3' '633' space space space space.
*--'Select at least one line'
    message s456(sd).
*   message s633(l3). "Message Class L3 not present in NW2004s
  endif.
endform. "EXPORT_TO_CLIPBOARD_SESS
*-----------------------------------------------------------------------
ranges:
  r_bname for usr02-bname
, r_nlast for adrp-name_last
.
form import_from_clipboard tables data_tab.
  call function 'CLPB_IMPORT'
       tables
         data_tab   = data_tab
       exceptions
         clpb_error = 1
         .
  if sy-subrc <> 0.
    app_log 'ED' '830' space space space space.
*--'Error when copying from clipboard'
    message e830(ed).
* else.
**  app_log 'ED' '???' space space space space.
**-'The block was copied from the buffer'
**  message s???(ed).
  endif.
endform. "IMPORT_FROM_CLIPBOARD
*-----------------------------------------------------------------------
form import_so_bname using f_replace.
  data:
    cnt_clipb_before type i
* , cnt_clipb_after  type i
  , cnt_so_before    type i
  , cnt_so_after     type i
  , cnt_total_added  type i
  .
  perform import_from_clipboard tables usrlist.
  describe table usrlist lines cnt_clipb_before.

  if cnt_clipb_before is initial.
    app_log_z2_0 '094'.
*--'Clipboard is empty'
    message s094.
    exit.
  endif.

  sort usrlist by bname.
  delete adjacent duplicates from usrlist.
* describe table usrlist lines cnt_clipb_after.

*-Which mode is used during clipboard import?
  if f_replace is initial.
*---ADD mode, remember number of entries before
    describe table so_bname lines cnt_so_before.
  else.
*---REPLACE mode, clear existing entries
    refresh so_bname.
  endif.

  loop at usrlist where not bname is initial.
    so_bname-sign = 'I'.
    if usrlist-bname cs '*'.
      so_bname-option = 'CP'.
    else.
      so_bname-option = 'EQ'.
    endif.
    so_bname-low  =  usrlist-bname.
    translate so_bname-low to upper case.
    append so_bname.
  endloop.

*-In case of import in ADD-mode we do not add any existing entries!
  if f_replace is initial.
    sort so_bname.
    delete adjacent duplicates from so_bname.

    describe table so_bname lines cnt_so_after.
*   if cnt_clipb_before is initial.
*     app_log_z2_0 '094'.
**---'Clipboard is empty'
*     message s094.
*   else.
      cnt_total_added = cnt_so_after - cnt_so_before.
      if cnt_total_added is initial.
        app_log_z2_0 '128'.
*------'Selection criteria stay unchanged'
        message s128.
      else.
        app_log_z2_3 '129' cnt_so_before cnt_total_added cnt_so_after.
*------'&1 + &2 = &3'
        message s129 with
          cnt_so_before
*         cnt_clipb_before
*         cnt_clipb_after
          cnt_total_added
          cnt_so_after
          .
      endif.
*   endif.
  else.
    describe table so_bname lines cnt_so_after.
    app_log_z2_1 '130' cnt_so_after.
*--'& entries imported'
    message s130 with cnt_so_after.
  endif.
endform. "IMPORT_SO_BNAME
*-----------------------------------------------------------------------
form import_and_prepare.
  perform import_from_clipboard tables usrlist.
  sort usrlist by bname.
  delete adjacent duplicates from usrlist.

  refresh r_bname.
  loop at usrlist.
    r_bname-sign   = 'I'.
    r_bname-option = 'EQ'.
    r_bname-low    =  usrlist-bname.
    translate r_bname-low to upper case.
    append r_bname.
  endloop.
endform. "IMPORT_AND_PREPARE
*-----------------------------------------------------------------------
form import_and_prepare_surname.
  perform import_from_clipboard tables surnames.

* wait up to 2 seconds.

  sort surnames by name_last.
  delete adjacent duplicates from surnames.
  delete surnames where name_last is initial.

  refresh r_nlast.
  loop at surnames.
    r_nlast-sign   = 'I'.
    r_nlast-option = 'EQ'.
    r_nlast-low    =  surnames-name_last.
*   translate r_nlast-low to upper case.
*   translate "urnames-name_last
*              r_nlast-low
*         from code page '1500'
*           to code page '1504'
*              .
    append r_nlast.
  endloop.
endform. "IMPORT_AND_PREPARE_SURNAME
*-----------------------------------------------------------------------
define mark_from_clipb.
  perform import_and_prepare.

  if r_bname[] is initial.
*--'Clipboard is empty'
    message s094.
  else.
    read table &1 index 1. &2 = 'X'.
    modify &1 transporting mark where bname in r_bname.

    free usrlist.
    perform &3.
  endif.
end-of-definition. "MARK_FROM_CLIPB
*-----------------------------------------------------------------------
define mark_from_clipb_surname.
  perform import_and_prepare_surname.

  if r_nlast[] is initial.
*--'Clipboard is empty'
    message s094.
  else.
    read table &1 index 1. &2 = 'X'.
    modify &1 transporting mark where name_last in r_nlast.

    free surnames.
    perform &3.
  endif.
end-of-definition. "MARK_FROM_CLIPB_SURNAME
*-----------------------------------------------------------------------
form mark_from_clipboard.
  if f_surnam is initial.
    perform mark_from_clipboard_main.
  else.
    perform mark_from_clipboard_main_sur.
  endif.
endform. "MARK_FROM_CLIPBOAD
*-----------------------------------------------------------------------
form mark_from_clipboard_main.
  mark_from_clipb         it    it-mark    print_table.
endform. "MARK_FROM_CLIPBOAD_MAIN
*-----------------------------------------------------------------------
form mark_from_clipboard_main_sur.
  mark_from_clipb_surname it    it-mark    print_table.
endform. "MARK_FROM_CLIPBOAD_MAIN_SUR
*-----------------------------------------------------------------------
form mark_from_clipboard_sess.
  mark_from_clipb         it41s it41s-mark print_table_s.
endform. "MARK_FROM_CLIPBOAD_SESS
*-----------------------------------------------------------------------
form f4_help_popup using tabname fieldname display
                changing returncode value
                         .
* fields-tabname   - tabname
* fields-fieldname - fieldname
* fields-fieldtext - display
* fields-value     - value
  if     tabname =  msg_tabn    and fieldname =  msg_fldn.
    perform get_message_from_list changing value.
  elseif tabname = 'T000'       and fieldname = 'MANDT'.
    perform get_mandt_from_list   changing value.
  elseif tabname = 'MSXXLIST'   and fieldname = 'NAME'.
    perform get_server_from_list  changing value.
  else.
    app_log 'S4' '780' tabname fieldname space space.
*--'No F4 help is available for & &'
    message s780(s4) with tabname fieldname.
  endif.
endform. "F4_HELP_POPUP
*-----------------------------------------------------------------------
form get_server_list tables t_srv structure msxxlist
                   changing rc    like      sy-subrc
                            .
  clear t_srv. refresh t_srv.
  call function 'TH_SERVER_LIST'
       tables
         list   = t_srv
       exceptions
         others = 99
         .
  rc = sy-subrc.
  if sy-subrc = 0. sort t_srv by name ascending. endif.
endform. "GET_SERVER_LIST
*-----------------------------------------------------------------------
form get_server_from_list changing l_srv.
  data:
    v_srv like temsg-applserver
  , begin of t_srvl occurs 0
  ,   name like msxxlist-name
  ,   host like msxxlist-host
  ,   serv like msxxlist-serv
  , end   of t_srvl
  .
  perform get_server_list tables t_srv changing rc.
  if rc <> 0.
    app_log_00_0 '623'.
*--'No server list received'
    message e623(00).
    exit.
  endif.

  free t_srvl.
  loop at t_srv.
    move-corresponding t_srv to t_srvl.
*   t_srvl-name = t_srv-name.
*   t_srvl-host = t_srv-host.
*   t_srvl-serv = t_srv-serv.
    append t_srvl.
  endloop.

  free t_fld.
  app_t_fld_s 'MSXXLIST' 'NAME'.
  app_t_fld   'MSXXLIST' 'HOST'.
  app_t_fld   'MSXXLIST' 'SERV'.
* app_t_fld   'MSXXLIST' 'MSGTYPES'.
* app_t_fld   'MSXXLIST' 'HOSTADR'.
* app_t_fld   'MSXXLIST' 'SERVNO'.

  fill_t_val t_srvl.

  call function 'HELP_VALUES_GET_WITH_TABLE'
       importing
         select_value = v_srv
       tables
         fields       = t_fld
         valuetab     = t_val
       exceptions
         others       = 99
         .
  if sy-subrc = 0. l_srv = v_srv. endif.
endform. "GET_SERVER_FROM_LIST
*-----------------------------------------------------------------------
form get_mandt_from_list changing l_mandt.
  data:
    v_mandt like t000-mandt
  , begin of t_man occurs 0
  ,   mandt      like t000-mandt
  ,   mtext      like t000-mtext
  ,   ort01      like t000-ort01
  ,   mwaer      like t000-mwaer
  ,   changeuser like t000-changeuser
  ,   changedate like t000-changedate
  ,   logsys     like t000-logsys
  , end   of t_man
  .
  free t_fld.
  app_t_fld_s 'T000' 'MANDT'.
  app_t_fld   'T000' 'MTEXT'.
  app_t_fld   'T000' 'ORT01'.
  app_t_fld   'T000' 'MWAER'.
  app_t_fld   'T000' 'CHANGEUSER'.
  app_t_fld   'T000' 'CHANGEDATE'.
  app_t_fld   'T000' 'LOGSYS'.

  free t_man.
  select * from t000 into corresponding fields of table t_man.

  fill_t_val t_man.

  call function 'HELP_VALUES_GET_WITH_TABLE'
       importing
         select_value = v_mandt
       tables
         fields       = t_fld
         valuetab     = t_val
       exceptions
         others       = 99
         .
  if sy-subrc = 0. l_mandt = v_mandt. endif.
endform. "GET_MANDT_FROM_LIST
*-----------------------------------------------------------------------
form get_message_from_list changing l_msg.
  data:
    v_msg like wptotlicer-com_error
  , begin of t_msg occurs 0
  ,   msg    like v_msg
  , end   of t_msg
  .
  free t_fld.
  app_t_fld_s msg_tabn msg_fldn.

  free t_msg.
  import last_msg to v_msg from memory id idxkey.

  if not v_msg is initial.
    append v_msg to t_msg.
  endif.

  if not t_msglst[] is initial.
    loop at t_msglst.
      append t_msglst-msg to t_msg.
    endloop.
  endif.

  fill_t_val t_msg.
*-Sort itab with specified sort keys instead of default sort key
  sort t_val by value.
  delete adjacent duplicates from t_val.

  if not t_val[] is initial.
    call function 'HELP_VALUES_GET_WITH_TABLE'
         importing
           select_value = v_msg
         tables
           fields       = t_fld
           valuetab     = t_val
         exceptions
           others       = 99
           .
    if sy-subrc = 0. l_msg = v_msg. endif.
  else.
    app_log_z2_2 '074' msg_tabn msg_fldn.
*--'No help for &1 &2 currently available'
    message s074 with msg_tabn msg_fldn.
  endif.
endform. "GET_MESSAGE_FROM_LIST
*-----------------------------------------------------------------------
form read_customer.
  data v_value type x value 0.

  move 0 to v_value.
  call 'GET_ACCESS_INFO'
    id 'CODE'    field v_value
    id 'LICENSE' field v_customer
    .
endform. "READ_CUSTOMER
*----------------------------------------------------------------------
form display_alv.
  check p_mandt = sy-mandt.
  cls usrlist.

* if expert is initial.
    loop at it assigning <fs>. "where mandt = sy-mandt.
      usrlist-bname = <fs>-bname. append usrlist.
    endloop.
* else.
*   select bname into corresponding fields of table usrlist
*                from usr02
*                     .
*   if sy-subrc <> 0. cls usrlist. endif.
* endif.

  check not usrlist[] is initial.
  call function 'SUSR_USERS_LIST_ALV'
       tables
         users = usrlist
         .
  free usrlist.
  perform simulate_sapgui_update.
endform. "DISPLAY_ALV
*----------------------------------------------------------------------
form move_pointer.
  get_and_check_sel_bname.
  if sel_bname <> point_bname.
    perform set_pointer.
*   perform simulate_sapgui_update.
    perform print_table.
    app_log_z2_2 '031' text-831 point_bname.
    message s031 with 'Pointer is set to user'(831) point_bname.
  endif.
endform. "MOVE_POINTER
*----------------------------------------------------------------------
form find_linked_users using v_mandt like sy-mandt
                             v_bname like sy-uname
                             .
  data:
    it_ref  type standard table of usrefus
  , v_refusers(70)

  , begin of it_ref2 occurs 0
  ,   mandt     like usrefus-mandt
  ,   sep1
  ,   bname     like usrefus-bname
  ,   sep2(3)
  ,   refuser   like usrefus-refuser
  ,   sep3
  ,   useralias like usrefus-useralias
  , end   of it_ref2

  , wa      like line of it_ref
  .
  refresh it_ref.
  select * from usrefus client specified
           into corresponding fields of table it_ref
           where mandt   = v_mandt
             and refuser = v_bname
                 .
  if sy-subrc = 0.
    move sy-dbcnt to s_dbcnt. condense s_dbcnt.
    concatenate s_dbcnt 'users are linked to'(958) v_mandt v_bname
           into v_refusers
                separated by space
                .
    refresh it_ref2. clear wa.
    loop at it_ref into wa.
      move-corresponding wa to it_ref2. append it_ref2.
    endloop.
    free it_ref.

    it_ref2-sep2 = '->'.
    modify it_ref2 transporting sep2 where sep2 is initial.
    editor-call for it_ref2 title v_refusers display-mode.
    free it_ref2.
  else.
    app_log_z2_3 '032'
      'No linked users were found for'(959) v_mandt v_bname.
    message s032 with text-959 v_mandt v_bname.
  endif.
endform. "FIND_LINKED_USERS
*----------------------------------------------------------------------
form clear_passw_hist using v_mandt like sy-mandt
                            v_bname like sy-uname
                            .
*-Check for active ARFC calls
  check_arfc.

  if enable_chk1 = 'X'.
    case sy-uname.
      when sapstar
        or admin_1
        or admin_2
        or admin_3
        or admin_4
        or admin_5
        or admin_6
        or admin_7
        or admin_8
        or admin_9
           .
      when others. exit.
    endcase.
  endif.

  select * from usr02 client specified
           where mandt = v_mandt
             and bname = v_bname
                 .
  endselect.

  if sy-subrc = 0.
*---------------------'in client'
    concatenate v_bname text-041 v_mandt '?'
           into pop_txt
                separated by space
                .
    confirm_step 'N'
                 'Reset password history for user'(954)
                  pop_txt
                 'Reset password history'(955)
                  .
    if ans = 'J'.
      usr02-ocod1 = usr02-ocod2 = usr02-ocod3 =
      usr02-ocod4 = usr02-ocod5 = usr02-bcode.
      modify usr02 client specified.
      if sy-subrc = 0.
        app_log_z2_3 '032'
          'Password history cleared for'(956) v_mandt v_bname.
        message s032 with text-956 v_mandt v_bname.
      endif.
    else. perform action_cancelled. endif.
  else.
*   app_log_z2_2 '004' v_bname v_mandt.
*--'User &1 in client &2 not found (inactive)'
*   message e004 with v_bname v_mandt.
    app_log '01' '124' v_bname space space space.
*--'User & does not exist'
    message i124(01) with v_bname.
  endif.
endform. "CLEAR_PASSW_HIST
*----------------------------------------------------------------------
form extended_action.
  data:
    s_email2clipb like spopli-varoption
  , s_delete_user like s_email2clipb
  , s_reset_phist like s_email2clipb
  , s_find_linked like s_email2clipb

  , begin of t_email occurs 1
  ,   v_email     like adr6-smtp_addr
  , end   of t_email

  , f_1
  , f_2
* , name_first    like adrp-name_first
* , name_last     like adrp-name_last
  .
  get_and_check_sel_bname.

  perform cleanup_spopli.

  perform get_smtp_address using p_mandt sel_bname
                        changing v_smtp_addr
                                 .
  if v_smtp_addr is initial.
    move '@00@E-mail not found'(953) to s_email2clipb.
  else.
    condense v_smtp_addr.
    concatenate '@2U@Copy <'(943) v_smtp_addr '>'
           into  s_email2clipb.
  endif.
  condense s_email2clipb.
  app_spopli 'X'  s_email2clipb                             ' '.
  app_spopli 'X' '@F8@View personal info'(944)              ' '.
  app_spopli 'X' '@96@Show spool for the last 30 days'(946) ' '.

  concatenate '@CQ@Find users linked to'(945) p_mandt sel_bname
         into  s_find_linked
               separated by space
               .
  condense s_find_linked.

  move '@BA@Clear password history'(947)
    to  s_reset_phist.

  if enable_chk1 = 'X'.
    case sy-uname.
      when sapstar
        or admin_1
        or admin_2
        or admin_3
        or admin_4
        or admin_5
        or admin_6
        or admin_7
        or admin_8
        or admin_9
           .
           f_1 = 'X'. f_2 = ' '.
      when others.
           f_1 = ' '. f_2 = 'X'.
*          move '@MG@No authorization for this action'(957)
*            to  s_reset_phist.
    endcase.
  endif.
  condense s_reset_phist.
  app_spopli f_1  s_reset_phist                             f_2.

  move '@11@Delete user... (check linked)'(948) to s_delete_user.
  if p_mandt = sy-mandt.
    f_1 = 'X'. f_2 = ' '.
*   move '@11@Delete user... (check linked)'(948) to s_delete_user.
  else.
    f_1 = ' '. f_2 = 'X'.
*   concatenate '@MG@Only available in client'(952) sy-mandt
*          into  s_delete_user
*                separated by space
*                .
  endif.
  condense s_delete_user.
  app_spopli f_1  s_delete_user                             f_2.

  concatenate 'Choose action for'(942) p_mandt sel_bname
         into  spop5titel
               separated by space
               .
  condense spop5titel.

  app_spopli 'X'  s_find_linked                             ' '.

  concatenate 'Available functions for account'(228)
               sy-sysid p_mandt sel_bname
         into  spop5txt1
               separated by space
               .
  condense spop5txt1.

*-Get long info
  read table it with key bname = sel_bname.
  if sy-subrc = 0.
    if it-name_first is initial and it-name_last is initial.
      clear spop5txt2.
    else.
      concatenate it-name_first it-name_last
             into spop5txt2
                  separated by space
                  .
      condense spop5txt2.
    endif.
    move it-function to spop5txt3.
  endif.

  call function 'POPUP_TO_DECIDE_LIST'
       exporting
         cursorline         =  def_radio
         mark_flag          = ' '
         mark_max           =   1
         start_col          =  25
         start_row          =   6
         textline1          =  spop5txt1
         textline2          =  spop5txt2
         textline3          =  spop5txt3
         titel              =  spop5titel
*        display_only       = ' '
       importing
         answer             =  ans
       tables
         t_spopli           =  it_spopli
       exceptions
         not_enough_answers =   1
         too_much_answers   =   2
         too_much_marks     =   3
         .
  if sy-subrc <> 0.
    app_log_z2_0 '090'.
*--'Internal error. This function is not possible.'
    message e090.
  elseif ans <> 'A'.
    case ans.
      when '1'. if not v_smtp_addr is initial.
                  refresh t_email. append v_smtp_addr to t_email.
                  perform export_to_clipboard tables t_email using 'X'.
                endif.
      when '2'. perform show_user_details using p_mandt sel_bname.
      when '3'. perform show_spool        using p_mandt sel_bname.
      when '4'. perform clear_passw_hist  using p_mandt sel_bname.
      when '5'. if p_mandt = sy-mandt.
                  perform delete_user     using         sel_bname.
                endif.
      when '6'. perform find_linked_users using p_mandt sel_bname.
      when others.
    endcase.
  else. perform action_cancelled. endif.

endform. "EXTENDED_ACTION
*-----------------------------------------------------------------------
*form extended_action.
*  data:
*    l_answer      value '1'
*  , v_title(70)
*  , s_email2clipb(40)
*  , s_delete_user like s_email2clipb
*  , s_reset_phist like s_email2clipb
*  , s_find_linked like s_email2clipb
*  , begin of t_email occurs 1
*  ,   v_email     like adr6-smtp_addr
*  , end   of t_email
*  .
*  get_and_check_sel_bname.
*
*  perform get_smtp_address using p_mandt sel_bname
*                        changing v_smtp_addr
*                                 .
*  if v_smtp_addr is initial.
*    move '@00@E-mail not found'(953) to s_email2clipb.
*  else.
*    condense v_smtp_addr.
*    concatenate '@2U@Copy <'(943) v_smtp_addr '>'
*           into  s_email2clipb.
*  endif.
*  condense s_email2clipb.
*
*  concatenate '@CQ@Find users linked to'(945) p_mandt sel_bname
*         into  s_find_linked
*               separated by space
*               .
*  condense s_find_linked.
*
*  if p_mandt = sy-mandt.
*    move '@11@Delete user... (check linked)'(948) to s_delete_user.
*  else.
*    concatenate '@MG@Only available in client'(952) sy-mandt
*           into  s_delete_user
*                 separated by space
*                 .
*  endif.
*  condense s_delete_user.
*
*  move '@BA@Clear password history'(947)
*    to  s_reset_phist.
*
*  if enable_chk1 = 'X'.
*    case sy-uname.
*      when sapstar
*        or admin_1
*        or admin_2
*        or admin_3
*        or admin_4
*        or admin_5
*        or admin_6
*        or admin_7
*        or admin_8
*        or admin_9
*           .
*      when others.
*        move '@MG@No authorization for this action'(957)
*          to  s_reset_phist.
*    endcase.
*  endif.
*  condense s_reset_phist.
*
*  concatenate 'Choose action for'(942) p_mandt sel_bname
*         into  v_title
*               separated by space
*               .
*  condense v_title.
*
*  call function 'WCFW_POPUP_RADIO'
*       exporting
*         i_title  =  v_title
*         i_txt1   =  s_email2clipb
*         i_txt2   = '@F8@View personal info'(944)
*         i_txt3   = '@96@Show spool for the last 30 days'(946)
*         i_txt4   =  s_reset_phist
*         i_txt5   =  s_delete_user
*         i_txt6   =  s_find_linked
*         i_choice =  l_answer
*       importing
*         e_choice =  l_answer
*         e_answer =  l_answer
*       exceptions
*         error    =  1
*         others   =  2
*         .
*  if sy-subrc <> 0.
*  else.
*    case l_answer.
*      when '1'. if not v_smtp_addr is initial.
*                  refresh t_email. append v_smtp_addr to t_email.
*                  perform export_to_clipboard tables t_email 'X'.
*                endif.
*      when '2'. perform show_user_details using p_mandt sel_bname.
*      when '3'. perform show_spool        using p_mandt sel_bname.
*      when '4'. perform clear_passw_hist  using p_mandt sel_bname.
*      when '5'. if p_mandt = sy-mandt.
*                  perform delete_user     using         sel_bname.
*                endif.
*      when '6'. perform find_linked_users using p_mandt sel_bname.
*      when others.
*    endcase.
*  endif.
*endform. "EXTENDED_ACTION
*-----------------------------------------------------------------------
form post_mark_case using v_cnt v_msgno.
  if v_cnt is initial.
    app_log_z2_0 '108'.
*--'No users of that kind were found'
    message s108.
  else.
    app_log_z2_0 v_msgno.
    message id 'Z2' type 'S' number v_msgno.
*      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform. "POST_MARK_CASE
*-----------------------------------------------------------------------
form post_mark_auto using v_msgno.
  data v_cnt like sy-tfill.

  clear v_cnt.
  loop at it assigning <fs> where mark = 'X'.
    add 1 to v_cnt.
  endloop.

  if v_cnt is initial.
    app_log_z2_0 '108'.
*--'No users of that kind were found'
    message s108.
  else.
    app_log_z2_0 v_msgno.
    message id 'Z2' type 'S' number v_msgno.
*      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform. "POST_MARK_AUTO
*-----------------------------------------------------------------------
form post_mark_auto_msg using v_msg.
  data v_cnt like sy-tfill.

  clear v_cnt.
  loop at it assigning <fs> where mark = 'X'.
    add 1 to v_cnt.
  endloop.

  if v_cnt is initial.
    app_log_z2_0 '108'.
*--'No users of that kind were found'
    message s108.
  else.
    app_log_z2_1 '030' v_msg.
    message s030 with v_msg.
  endif.
endform. "POST_MARK_AUTO_MSG
*-----------------------------------------------------------------------
form cmd_select_yellow.
  if sum_err > 0.
    perform select_yellow.
    perform print_table.
  endif.

*'Users with incorrect logon attempts were marked'
  perform post_mark_case using sum_err '116'.
endform. "CMD_SELECT_YELLOW
*-----------------------------------------------------------------------
form select_yellow.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where locnt gt 0
*                               and uflag eq c_not_locked
                                and uflag ne c_locked_by_admin
                                and uflag ne c_locked_by_global_admin
                                and uflag ne c_locked_by_failed_logon
                                    .
endform. "SELECT_YELLOW
*-----------------------------------------------------------------------
form cmd_select_red.
  if sum_lck > 0.
    perform select_red.
    perform print_table.
  endif.

*'Locked users were marked'
  perform post_mark_case using sum_lck '117'.
endform. "CMD_SELECT_RED
*-----------------------------------------------------------------------
form select_red.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where uflag <> 0.
endform. "SELECT_RED
*-----------------------------------------------------------------------
form cmd_select_red_adm.
  perform select_red_adm.
  perform print_table.

*'Users locked by administator were marked'
  perform post_mark_auto using '118'.
endform. "SELECT_RED_ADM
*-----------------------------------------------------------------------
form select_red_adm.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where uflag = c_locked_by_global_admin
                                 or uflag = c_locked_by_admin
                                    .
endform. "SELECT_RED_ADM
*-----------------------------------------------------------------------
form cmd_select_red_err.
  perform select_red_err.
  perform print_table.

*'Users locked by incorrect logons were marked'
  perform post_mark_auto using '119'.
endform. "CMD_SELECT_RED_ERR
*-----------------------------------------------------------------------
form select_red_err.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where uflag = c_locked_by_failed_logon.
endform. "SELECT_RED_ERR
*-----------------------------------------------------------------------
define mac_mark_mass.
  &1 = &2.
  modify &3 transporting mark where &4 = &5.
end-of-definition. "MAC_MARK_MASS
*-----------------------------------------------------------------------
form cmd_select_with_refuser.
  perform select_with_refuser.
  perform print_table.

*'Users with reference user were marked'
  perform post_mark_case using sum_ref '120'.
endform. "CMD_SELECT_WITH_REFUSER
*-----------------------------------------------------------------------
form select_with_refuser.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where not refuser is initial.
endform. "SELECT_WITH_REFUSER
*-----------------------------------------------------------------------
form cmd_select_old.
  data tmp(70).

  perform select_old.
  perform print_table.

  tmp = 'Users with last reg. <= & were marked'(280).
  replace amp with s_datum into tmp.

  perform post_mark_auto_msg using tmp.
endform. "SELECT_OLD
*-----------------------------------------------------------------------
form select_old.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where trdat <= x_datum
                                and erdat <= x_datum
                                    .
endform. "SELECT_OLD
*-----------------------------------------------------------------------
form cmd_select_new.
  data tmp(70).

  perform select_new.
  perform print_table.

  tmp = 'Users created after & were marked'(281).
  replace amp with s_datum into tmp.

  perform post_mark_auto_msg using tmp.
endform. "CMD_SELECT_NEW
*-----------------------------------------------------------------------
form select_new.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where erdat >= x_datum.
endform. "SELECT_NEW
*-----------------------------------------------------------------------
form cmd_select_not_used.
  perform select_not_used.
  perform print_table.

*'Users with unused logins were marked'
  perform post_mark_case using sum_ini '123'.
endform. "CMD_SELECT_NOT_USED
*-----------------------------------------------------------------------
form select_not_used.
  perform select_none.
* it-mark = 'X'.
* modify it transporting mark where trdat is initial.
  mac_mark_mass it-mark    'X' it    trdat  '00000000'.
endform. "SELECT_NOT_USED
*-----------------------------------------------------------------------
form cmd_select_noclass.
  perform select_noclass.
  perform print_table.

*'Users with empty class (security group) were marked'
  perform post_mark_auto using '124'.
endform. "CMD_SELECT_NOCLASS
*-----------------------------------------------------------------------
form select_noclass.
  perform select_none.
  mac_mark_mass it-mark    'X' it    class   space.
endform. "SELECT_NOCLASS
*-----------------------------------------------------------------------
form cmd_select_nondia.
  perform select_nondia.
  perform print_table.

*'Users with type other than A were marked'
  perform post_mark_auto using '125'.
endform. "CMD_SELECT_NONDIA
*-----------------------------------------------------------------------
form select_nondia.
  perform select_none.
  it-mark = 'X'.
  modify it transporting mark where ustyp ne 'A'.
* mac_mark_mass it-mark    'X' it    ustyp   space.
endform. "SELECT_NONDIA
*-----------------------------------------------------------------------
form cmd_select_noaddr.
  perform select_noaddr.
  perform print_table.

*'Users without address data were marked'
  perform post_mark_case using sum_miss '126'.
endform. "CMD_SELECT_NOADDR
*-----------------------------------------------------------------------
form select_noaddr.
  perform select_none.
  mac_mark_mass it-mark    'X' it    noaddr 'X'.
endform. "SELECT_NOADDR
*-----------------------------------------------------------------------
form cmd_select_online.
  perform select_online.
  perform print_table.

*'Online users were marked'
  perform post_mark_case using sum_act '127'.
endform. "CMD_SELECT_ONLINE
*-----------------------------------------------------------------------
form select_online.
  perform select_none.
  mac_mark_mass it-mark    'X' it    online 'X'.
endform. "SELECT_ONLINE
*-----------------------------------------------------------------------
form cmd_select_all.
  f_sele = 'X'.
  perform select_all.
  perform print_table.
endform. "CMD_SELECT_ALL
*-----------------------------------------------------------------------
form select_all.
  mac_mark_mass it-mark    'X' it    mark   ' '.
endform. "SELECT_ALL
*-----------------------------------------------------------------------
form cmd_select_all_s.
  perform select_all_s.
  perform print_table_s.
endform. "CMD_SELECT_ALL_S
*-----------------------------------------------------------------------
form select_all_s.
  mac_mark_mass it41s-mark 'X' it41s mark   ' '.
endform. "SELECT_ALL_S
*-----------------------------------------------------------------------
form cmd_select_none.
  f_sele = ' '.
  perform select_none.
  perform print_table.
endform. "CMD_SELECT_NONE
*-----------------------------------------------------------------------
form select_none.
  mac_mark_mass it-mark    ' ' it    mark   'X'.
endform. "SELECT_NONE
*-----------------------------------------------------------------------
form cmd_select_none_s.
  perform select_none_s.
  perform print_table_s.
endform. "CMD_SELECT_NONE_S
*-----------------------------------------------------------------------
form select_none_s.
  mac_mark_mass it41s-mark ' ' it41s mark   'X'.
endform. "SELECT_NONE_S
*-----------------------------------------------------------------------
form cmd_invert.
  perform invert.
  perform print_table.
endform. "S_INVERT
*-----------------------------------------------------------------------
form invert.
  mac_mark_mass it-mark    'A' it    mark   'X'.
  mac_mark_mass it-mark    'X' it    mark   ' '.
  mac_mark_mass it-mark    ' ' it    mark   'A'.
endform. "INVERT
*-----------------------------------------------------------------------
form cmd_invert_s.
  perform invert_s.
  perform print_table_s.
endform. "CMD_INVERT_S
*-----------------------------------------------------------------------
form invert_s.
  mac_mark_mass it41s-mark 'A' it41s mark   'X'.
  mac_mark_mass it41s-mark 'X' it41s mark   ' '.
  mac_mark_mass it41s-mark ' ' it41s mark   'A'.
endform. "INVERT_S
*-----------------------------------------------------------------------
form init_block.
  clear: f_1stmark, mark1, mark2.
endform. "INIT_BLOCK
*-----------------------------------------------------------------------
form init_block_s.
  clear: f_1stmark_s, mark1_s, mark2_s.
endform. "INIT_BLOCK_S
*-----------------------------------------------------------------------
form select_block.
  get_and_check_sel_bname.
  data tmp_idx like sy-tabix.
  perform toggle_flag changing f_1stmark.
  read table it with key mandt = p_mandt
                         bname = sel_bname
                         .
  if sy-subrc = 0.
    if f_1stmark = 'X'.
      mark1 = sy-tabix.
      app_log_z2_1 '093' sel_bname.
*----'& is beginning of block. Choose the end of block.'.
      message s093 with sel_bname.
    else.
      mark2 = sy-tabix.
      if mark1  > mark2.
        tmp_idx = mark1.
        mark1   = mark2.
        mark2   = tmp_idx.
      endif.
      loop at it assigning <fs> from mark1 to mark2.
        <fs>-mark = 'X'.
      endloop.
      perform print_table.
    endif.
  else. perform init_block. endif.
endform. "SELECT_BLOCK
*-----------------------------------------------------------------------
form select_block_s.
  get_and_check_sel_bname.
  data tmp_idx like sy-tabix.
  perform toggle_flag changing f_1stmark_s.
  read table it41s with key mandt  = it41s-mandt
                            bname  = it41s-bname
                            termid = it41s-termid
                            server = it41s-server
                            .
  if sy-subrc = 0.
    if f_1stmark_s = 'X'.
      mark1_s = sy-tabix.
      app_log_z2_1 '093' it41s-bname.
*----'& is beginning of block. Choose the end of block.'.
      message s093 with it41s-bname.
    else.
      mark2_s = sy-tabix.
      if mark1_s  > mark2_s.
        tmp_idx   = mark1_s.
        mark1_s   = mark2_s.
        mark2_s   = tmp_idx.
      endif.
      loop at it41s assigning <fs2> from mark1_s to mark2_s.
        <fs2>-mark = 'X'.
      endloop.
      perform print_table_s.
    endif.
  else. perform init_block_s. endif.
endform. "SELECT_BLOCK_S
*-----------------------------------------------------------------------
form mark_unmark_user.
  read table it with key mandt = p_mandt
                         bname = sel_bname
                         .
  if sy-subrc = 0.
    perform toggle_flag changing it-mark.
    modify it index sy-tabix.
  endif.
endform. "MARK_UNMARK_USER
*-----------------------------------------------------------------------
form mark_unmark_user_s.
  read table it41s with key mandt  = it41s-mandt
                            bname  = it41s-bname
                            termid = it41s-termid
                            server = it41s-server
                            .
  if sy-subrc = 0.
    perform toggle_flag changing it41s-mark.
    modify it41s index sy-tabix.
  endif.
endform. "MARK_UNMARK_USER_S
*-----------------------------------------------------------------------
form toggle_user.
  get_and_check_sel_bname.
  perform mark_unmark_user.
  if p_prn is initial.
    if it-mark = 'X'.
      modify current line field format
        it-bname      color = mrk
        it-name_last  color = mrk
        it-name_first color = mrk

        it-tel_number color = mrk
        it-tel_numdis color = mrk
        it-tel_extens color = mrk

        it-function   color = mrk
        it-department color = mrk
        it-building   color = mrk
        it-roomnumber color = mrk
        .
    else.
      if sel_bname = point_bname and p_point = 'X'.
        modify current line field format
          it-bname      color = pnt
          it-name_last  color = pnt
          it-name_first color = pnt

          it-tel_number color = pnt
          it-tel_numdis color = pnt
          it-tel_extens color = pnt

          it-function   color = pnt
          it-department color = pnt
          it-building   color = pnt
          it-roomnumber color = pnt
          .
      else.
        if f_chkaddr is initial or it-noaddr is initial.
          modify current line field format
            it-bname      color = c01
            it-name_last  color = c02
            it-name_first color = c02

            it-tel_number color = c04
            it-tel_numdis color = c04
            it-tel_extens color = c04

            it-function   color = c06
            it-department color = c06
            it-building   color = c06
            it-roomnumber color = c06
            .
        else.
          modify current line field format
            it-bname      color = cl_noaddr
            it-name_last  color = cl_noaddr
            it-name_first color = cl_noaddr

            it-tel_number color = cl_noaddr
            it-tel_numdis color = cl_noaddr
            it-tel_extens color = cl_noaddr

            it-function   color = cl_noaddr
            it-department color = cl_noaddr
            it-building   color = cl_noaddr
            it-roomnumber color = cl_noaddr
            .
        endif.
        case it-uflag.
          when c_not_locked.
*--------------Not locked users, nothing to do
               if it-locnt > 0.
*----------------Users with failed logons, highlight with CL_FAILED
                 modify current line field format
                   it-bname color = cl_failed.
               endif.
          when c_locked_by_admin
            or c_locked_by_global_admin
            or c_locked_by_failed_logon.
*--------------Locked users, highlight with CL_LOCKED
               modify current line field format
                 it-bname color = cl_locked.
          when others.
*--------------Users with unknown status, highlight with CL_UNKNOWN
               modify current line field format
                 it-bname color = cl_unknown.
        endcase.
      endif.
    endif.
  endif.
  modify current line field value it-mark from it-mark.
endform. "TOGGLE_USER
*-----------------------------------------------------------------------
form toggle_user_s.
  perform mark_unmark_user_s.
  mac_determine_colors_s.
  modify current line field format
    it41s-mandt      color = col_mandt_s
    it41s-bname      color = col_sess
    it41s-name_last  color = col_sess
    it41s-name_first color = col_sess
    .
  modify current line field value it41s-mark from it41s-mark.
endform. "TOGGLE_USER_S
*-----------------------------------------------------------------------
define delete_where_mark_ex.
  delete it where mark = &1.
  ind_crop = '*'. "Set CROPPED indicator
end-of-definition. "DELETE_WHERE_MARK_EX
*-----------------------------------------------------------------------
define delete_where_mark.
  check_mark_exists.
  if sy-subrc = 0.
    delete_where_mark_ex &1.
    perform print_table.
    perform jump_to_first_page.
  else.
    app_log 'L3' '633' space space space space.
*--'Select at least one line'
    message s456(sd).
*   message s633(l3). "Message Class L3 not present in NW2004s
  endif.
end-of-definition. "DELETE_WHERE_MARK
*-----------------------------------------------------------------------
form crop_list_ex.
  delete_where_mark_ex ' '.
endform. "CROP_LIST_EX
*-----------------------------------------------------------------------
form exclude_from_list.
  delete_where_mark    'X'.
endform. "EXCLUDE_FROM_LIST
*-----------------------------------------------------------------------
form crop_list.
  delete_where_mark    ' '.
endform. "CROP_LIST
*-----------------------------------------------------------------------
form remove_link using v_mandt like sy-mandt v_bname like sy-uname.
  plunger.
*  if v_mandt <> sy-mandt.
**   message e... with ...
*  else.
**---Remove
**   confirm_step
**     'Y'
**     ...
**   if ans = 'J'.
**     .. remove ..
**   else. perform action_cancelled. endif.
*  endif.
endform. "REMOVE_LINK
*-----------------------------------------------------------------------
form at_link_click.
  data:
    v_man_bname(16)
  , s_colinked like spopli-varoption
  , s_linkedto like spopli-varoption
  , s_remove   like spopli-varoption
  .
  get_and_check_sel_bname.

  perform cleanup_spopli.

  concatenate p_mandt sel_bname into v_man_bname separated by space.
  condense v_man_bname.

  spop5txt1 = 'The user &1 has reference to user &2'(888).
  spop5txt2 =
    'That is, he or she has all of auths of reference user.'(889).
  spop5txt3 = 'Would you like to...'(890).

  repl2 amp1 v_man_bname spop5txt1.
  repl2 amp2 it-refuser  spop5txt1.

  s_remove   = '@CR@ Remove reference to user &'(893).
  s_colinked = '@13@ Find all users linked to user &'(891).
  s_linkedto = '@CQ@ Find all users linked to user &'(892).

  spop5titel = '&1 linked to user &2'(894).

  repl2 amp1 v_man_bname spop5titel.
  repl2 amp2 it-refuser  spop5titel.
  repl2 amp  it-refuser  s_colinked.
  repl2 amp  it-bname    s_linkedto.
  repl2 amp  it-refuser  s_remove.

  def_radio = 2.
  if p_mandt = sy-mandt.
*   def_radio = 2.

    app_spopli 'X' s_remove   ' '.
    app_spopli 'X' s_colinked ' '.
    app_spopli 'X' s_linkedto ' '.
  else.
*   def_radio = 2.

    app_spopli 'X' s_remove   'X'.
    app_spopli 'X' s_colinked ' '.
    app_spopli 'X' s_linkedto ' '.
  endif.

  call function 'POPUP_TO_DECIDE_LIST'
       exporting
         cursorline         =  def_radio
         mark_flag          = ' '
         mark_max           =   1
         start_col          =  25
         start_row          =   6
         textline1          =  spop5txt1
         textline2          =  spop5txt2
         textline3          =  spop5txt3
         titel              =  spop5titel
*        display_only       = ' '
       importing
         answer             =  ans
       tables
         t_spopli           =  it_spopli
       exceptions
         not_enough_answers =   1
         too_much_answers   =   2
         too_much_marks     =   3
         .
  if sy-subrc <> 0.
    app_log_z2_0 '090'.
*--'Internal error. This function is not possible.'
    message e090.
  elseif ans <> 'A'.
    case ans.
      when '1'. perform remove_link       using it-mandt it-bname.
      when '2'. perform find_linked_users using  p_mandt it-refuser.
      when '3'. perform find_linked_users using  p_mandt it-bname.
    endcase.
  else. perform action_cancelled. endif.
endform. "AT_LINK_CLICK
*-----------------------------------------------------------------------
form switch_cmd_mode.
  data:
    s_search   like spopli-varoption
  , s_mark     like spopli-varoption
  , s_filter   like spopli-varoption
  , s_command  like spopli-varoption
  .
  perform cleanup_spopli.

  spop5titel = 'Choose one of available modes'(335).
  spop5txt1  = 'Note that you may execute a command in any mode'(336).
  spop5txt2  =
    'just typing it in command line with special prefix &'(337).
  replace amp with cmd_tag into spop5txt2.

  spop5txt3  = 'Doubleclick command line to get list of commands'(334).

  s_search   = '@JH@ Search mode (jump to entry found)'(330).
  s_mark     = '@8G@ Mark mode (mark found entries)'(331).
  s_filter   = '@4G@ Filter mode (filter found entries)'(332).
  s_command  = '@AJ@ Command mode (command execution)'(333).

  case mode_icon.
    when icon_extended_search. def_radio = 1.
    when icon_set_copy_in_b  . def_radio = 2.
    when icon_filter         . def_radio = 3.
    when icon_working_plan   . def_radio = 4.
    when others              . def_radio = 1.
  endcase.

  app_spopli 'X' s_search  ' '.
  app_spopli 'X' s_mark    ' '.
  app_spopli 'X' s_filter  ' '.
  app_spopli 'X' s_command ' '.

  call function 'POPUP_TO_DECIDE_LIST'
       exporting
         cursorline         =  def_radio
         mark_flag          = ' '
         mark_max           =   1
         start_col          =  25
         start_row          =   6
         textline1          =  spop5txt1
         textline2          =  spop5txt2
         textline3          =  spop5txt3
         titel              =  spop5titel
*        display_only       = ' '
       importing
         answer             =  ans
       tables
         t_spopli           =  it_spopli
       exceptions
         not_enough_answers =   1
         too_much_answers   =   2
         too_much_marks     =   3
         .
  if sy-subrc <> 0.
    app_log_z2_0 '090'.
*--'Internal error. This function is not possible.'
    message e090.
  elseif ans <> 'A'.
*---Redundant cleanup (for safety)
    perform set_new_search.
    case ans.
      when '1'. perform cmd_search_mode. "<- Cleanup is inside that form
      when '2'. perform cmd_mark_mode.   "<- Cleanup is inside that form
      when '3'. perform cmd_filter_mode. "<- Cleanup is inside that form
      when '4'. perform cmd_command_mode."<- Cleanup is inside that form
    endcase.
  else. perform action_cancelled. endif.
endform. "SWITCH_CMD_MODE
*-----------------------------------------------------------------------
form call_rfc_ping_wait.
  data v_msg(80).                                        "#EC NEEDED

  if p_aref is initial or busy_cnt > 1. exit. endif.

  add 1 to busy_cnt. "Increase counter of performed ARFC pings

*-Wait in a task
  call function 'SPTA_RFC_PING_AND_WAIT'
       starting new task '001'
       performing
         at_end_of_task on end of task
       exporting
         seconds               = arfc_secs  " Refresh time
*        block_target_wp       =
       exceptions
         resource_failure      = 1
         communication_failure = 2 message v_msg
         system_failure        = 3 message v_msg
         others                = 4
         .
  case sy-subrc.
    when 0.
*   when 2 or 3.
*     message i030 with v_msg.
    when others.
      subtract 1 from busy_cnt. "ARFC ping failed, decrease counter
*     message i030 with 'Error during RFC ping and wait'(789).
  endcase.
endform. "CALL_RFC_WAIT
*----------------------------------------------------------------------
form at_end_of_task using u_taskname.
  data v_msg(80).                                        "#EC NEEDED
  subtract 1 from busy_cnt.
* Receiving task results
  receive results from function 'SPTA_RFC_PING_AND_WAIT'
    exceptions
      resource_failure      = 1
      communication_failure = 2 message v_msg
      system_failure        = 3 message v_msg
      others                = 4
      .
  case sy-subrc.
    when 0.
      if p_aref = 'X' and busy_cnt is initial.
        set user-command 'REFR'.            " Refresh
      else.
        clear busy_cnt.
      endif.
    when 2 or 3.
      clear: p_aref, busy_cnt.
      app_log_z2_1 '030' v_msg.
*     message s030 with v_msg.
      set user-command 'REFR'.            " Refresh
    when others.
      clear: p_aref, busy_cnt.
      app_log_z2_0 '109'.
*----'Error receiving ARFC task results'
*     message s109.
      set user-command 'REFR'.            " Refresh
  endcase.
endform. "AT_END_OF_TASK
*----------------------------------------------------------------------
*form write_to_html.
*  data:
*    filename like rlgrap-filename
*  , html     type table of w3html    "For the lists <= 255 chars
*  , sep(1)   value '_'
*  , list_idx like sy-lsind
*  .
*  list_idx = sy-lsind - 1.
** Now take list buffer and convert this to HTML for output
*  call function 'WWW_LIST_TO_HTML'
*       exporting
*         list_index = list_idx
*       tables
*         html       = html
*         .
** break ared.
*  concatenate 'C:\' sy-repid sep sy-sysid sep sy-mandt sep
*                    sy-datum sep sy-uzeit '.html'
*         into  filename
*               .
*  condense filename.
*  call function 'WS_DOWNLOAD'
*       exporting
*         filename = filename
*       tables
*         data_tab = html
*       exceptions
*         others   = 99
*         .
*  if sy-subrc <> 0.
*    message i047 with 'HTML' filename.
*  else.
*    message s042 with        filename.
*  endif.
*endform. "WRITE_TO_HTML
*-----------------------------------------------------------------------
form export_to_excel_main.
* data et type standard table of ty_it with header line.

  if fm_to_excel-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_to_excel-name.
*--'Called function module does not exist in the system &' + &V2&
    message w063 with sy-sysid fm_to_excel-name.
  elseif f_javagui = 'X'.
*---SAPGUI for Java is not currently supported here :-(
    app_log_z2_1 '030' text-342.
    message s030
       with 'The function is not implemented for Java environment'(342).
    exit.
  else.
*   clear et[].

*   loop at it assigning <fs>.
*     et-mandt      = <fs>-mandt     .
*     et-bname      = <fs>-bname     .
*     et-erdat      = <fs>-erdat     .
*     et-trdat      = <fs>-trdat     .
*     et-ltime      = <fs>-ltime     .
*     et-name_first = <fs>-name_first.
*     et-name_last  = <fs>-name_last .
*     et-department = <fs>-department.
*     et-function   = <fs>-function  .
*     et-tel_number = <fs>-tel_number.
*     append et.
*   endloop.

    call function fm_to_excel-name
         exporting
           template_id = 1
         tables
           data_tab    = it
           .
  endif.
endform. "EXPORT_TO_EXCEL_MAIN
*-----------------------------------------------------------------------
form export_to_excel_sess.
* data et41s type standard table of ty_it41s with header line.
  data template_id type i.

  if fm_to_excel-exists is initial.
    app_log_z2_2 '063' sy-sysid fm_to_excel-name.
*--'Called function module does not exist in the system &' + &V2&
    message w063 with sy-sysid fm_to_excel-name.
  elseif f_javagui = 'X'.
*---SAPGUI for Java is not currently supported here :-(
    app_log_z2_1 '030' text-342.
    message s030
       with 'The function is not implemented for Java environment'(342).
    exit.
  else.
*   clear et41[].
*
*   loop at it41s assigning <fs2>.
*     et41s-mandt      = <fs2>-mandt     .
*     et41s-bname      = <fs2>-bname     .
*     et41s-name_first = <fs2>-name_first.
*     et41s-name_last  = <fs2>-name_last .
*     et41s-terminal   = <fs2>-terminal  .
*     et41s-diff       = <fs2>-time      .
*     et41s-diff       = <fs2>-diff      .
*     et41s-server     = <fs2>-server    .
*     et41s-tcode      = <fs2>-tcode     .
*     et41s-page       = <fs2>-page      .
*     et41s-roll       = <fs2>-roll      .
*     et41s-memsum     = <fs2>-memsum    .
*     et41s-privsum    = <fs2>-privsum   .
*     append et41s.
*   endloop.

    if p_detail is initial. template_id = 2.
                      else. template_id = 3. endif.

    call function fm_to_excel-name
         exporting
           template_id = template_id
         tables
           data_tab    = it41s
           .
  endif.
endform. "EXPORT_TO_EXCEL_SESS
*-----------------------------------------------------------------------
define add_html_line.
  call method dd->add_static_html
       exporting
         string_with_html = &1
         .
end-of-definition. "ADD_HTML_LINE
*-----------------------------------------------------------------------
define add_html_link.
  call method dd->add_link
       exporting
         name    = &1
         url     = &2
         tooltip = &3
         text    = &4
       importing
         link    = dd_link
         .
end-of-definition. "ADD_HTML_LINK
*-----------------------------------------------------------------------
define add_icon.
  call method dd->add_icon
       exporting
         sap_icon = &1
         .
end-of-definition. "ADD_ICON
*-----------------------------------------------------------------------
define html_underline.
  call method dd->underline.
end-of-definition. "HTML_UNDERLINE
*-----------------------------------------------------------------------
define html_new_line.
  call method dd->new_line.
end-of-definition. "HTML_NEW_LINE
*-----------------------------------------------------------------------
form create_container.
  create object dc
         exporting
*          parent                      =
           repid                       = 'SAPMSSY0'
           dynnr                       = '0120'
*          side                        =  2
           side                        =
*            cl_gui_docking_container=>dock_at_bottom
*            cl_gui_docking_container=>dock_at_top
             cl_gui_docking_container=>dock_at_right
*            cl_gui_docking_container=>dock_at_left
           extension                   =  305
*          style                       =
*          lifetime                    =  lifetime_default
*          caption                     =
*          metric                      =  0
*          ratio                       =
*          no_autodef_progid_dynnr     =
*          name                        =
         exceptions
           cntl_error                  =  1
           cntl_system_error           =  2
           create_error                =  3
           lifetime_error              =  4
           lifetime_dynpro_dynpro_link =  5
           others                      =  6
           .
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
       with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform. "CREATE_CONTAINER
*-----------------------------------------------------------------------
data v_ext(4) value '.GIF'.

form change_extension.
*-Check for active ARFC calls
  check_arfc.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  a_flds 'T001'
         'BUKRS'
         'Extension'(418)
          v_ext
          .
* clear ans.
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     = 'Change extension for media content'(419)
         start_column    =  10
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'.
    r_flds 1 v_ext.
    if not last_html_bname is initial.
      perform build_document using last_html_bname.
    endif.
  endif.

  free fields.
endform. "CHANGE_EXTENSION
*-----------------------------------------------------------------------
form build_document using v_bname like usr02-bname.
  constants
    c_alter(14) value '_[alternative]'                   "#EC NOTEXT
  .
  data:
    v_alt(255)
  , nbsp(6)       value '&nbsp;' "SPACE token in HTML
  , v_alter       like c_alter
* , dd_t1         like sy-uzeit
* , dd_t2         like dd_t1
* , dd_delta      like dd_t1
  , specific_line like str_html
  , idx           like sy-tabix
  , tmp_line(255)
  .
*--------------------------------
*-Modify background
define modify_background.
  specific_line = '<STYLE>BODY{ background-color:#'.
  search dd->html_table for specific_line.
  if sy-tabix ne 0.
    idx = sy-tabix.
    read table dd->html_table index idx into specific_line.
*---Type conversion: STRING -> C
    move specific_line to tmp_line.
*---Replace background color
    tmp_line+31(6) = bg_color.
*---Type conversion: C -> STRING
    move tmp_line to specific_line.
    modify dd->html_table from specific_line index idx.
  endif.
end-of-definition. "MODIFY_BACKGROUND
*--------------------------------
define prepare_photo.
*-User's photo

  if f_altpict is initial.
*---Use standard user's photo
    clear v_alter.
  else.
*---Use alternative user's photo
    v_alter = c_alter.
  endif.

  if v_photos is initial.
*---Suggest to setup customizing
    concatenate
                'Full path to shared resource must be set in table'(356)
                 loctab
                'under key'(357)
                 key_photos
                ', for example: \\server1\R3photos\'(358)
           into  v_alt
                 separated by space
                 .
    condense v_alt.
  else.
    concatenate
                 v_bname
                 v_alter
                 v_ext
           into  v_alt
                 .
    condense v_alt.
    concatenate
                'Photo'(355)
                 v_alt
                '(you can disable it by entering CONN in OK-code)'(368)
           into  v_alt
                 separated by space
                 .
    condense v_alt.
  endif.

  if f_resize is initial.
*---Show a photo in original size
    concatenate
*               '<a href="'
*                v_photos
*               '">'
*               '" target="_blank">'
                '<img src="'
                 v_photos
                 v_bname
                 v_alter
                 v_ext
                '" alt="'
                 v_alt
                '" border=0>'
*               '</a>'
           into  str_html
                 .
  else.
*---Show a photo in fixed size
    concatenate
*               '<a href="'
*                v_photos
*               '">'
*               '" target="_blank">'
                '<img src="'
                 v_photos
                 v_bname
                 v_alter
                 v_ext
                '" width=222 height=240 alt="'
                 v_alt
                '" border=0>'
*               '</a>'
           into  str_html
                 .
  endif.
end-of-definition. "PREPARE_PHOTO
*--------------------------------
define prepare_badres_block.
  concatenate
              '<font color="000000" size="1">'
              'access to resource'(361)
              '<br><br>'
               v_photos
              '<br><br>'
              'has been disabled to prevent connection problem.'(362)
               nbsp
              'To reenable connection attempts again, please enter'(363)
               nbsp
              'CONN in OK-code.'(364)
              '<br><br>'
              'To change path to resource, enter PATH'(377)
              '</font>'
         into  str_html
               .
end-of-definition. "PREPARE_BADRES_BLOCK
*--------------------------------
  last_html_bname = v_bname.

  if dc is initial. perform create_container. endif.
  if dd is initial. create object dd.         endif.
*-Safety check
  if dc is initial or dd is initial. exit.    endif.

*-Initialization
  call method dd->initialize_document.

  condense v_bname.

* html_new_line.

*-Title
* concatenate
*             '<font color="DFDFDF" size="1">'
*              sy-sysid
*             '&nbsp;'
*              p_mandt
*             '</font>'
*        into  str_html
*              separated by space
*              .
* condense str_html.
* add_html_line str_html.
  html_new_line.

* if f_altpict is initial.
    concatenate
                '<font color="0000FF"><h2>'
                 v_bname
                '</h2></font>'
           into  str_html
                 separated by space
                 .
* else.
*   concatenate
*               '<font color="FFFF00"><h2>'
*               '<marquee bgcolor=#00DD00>'
*                v_bname
*               '</marquee>'
*               '</h2></font>'
*          into  str_html
*                separated by space
*                .
* endif.

  condense str_html.
  add_html_line str_html.

  html_underline.

*-User's photo
  if f_badres is initial.
    prepare_photo.
  else.
    prepare_badres_block.
  endif.
  condense str_html.
  add_html_line str_html.

  html_underline.
  html_new_line.

*-Get user's name & surname:
* first, read an internal table (faster!)
  read table it with key mandt = p_mandt
                         bname = v_bname
                         .
* then, if entry not found, read data from DB
  if sy-subrc <> 0.
    perform get_user_name
                    using p_mandt       v_bname
                 changing it-name_first it-name_last
                          .
  endif.

*-Last name
  concatenate
              '<b><i><font size="3" color="0044FF">'
               it-name_last
              '</font></i></b><br>'
         into  str_html
               separated by space
               .
  condense str_html.

  add_html_line str_html.

*-First name
  concatenate
              '<b><i><font size="3" color="0044FF">'
               it-name_first
              '</font></i></b>'
         into  str_html
               separated by space
               .
  condense str_html.

  add_html_line str_html.

  read table it with key mandt = p_mandt bname = v_bname.
  if sy-subrc = 0.
    html_new_line.

*---Function
    html_new_line.
    concatenate
                '<font size="2" color="0044FF">'
                 it-function
                '</font>'
           into  str_html
                 separated by space
                 .
    condense str_html.
    add_html_line str_html.

*---Department
    html_new_line.
    concatenate
                '<font size="1" color="0044FF">'
                 it-department
                '</font>'
           into  str_html
                 separated by space
                 .
    condense str_html.
    add_html_line str_html.
    html_new_line.

*---Telephone
    if not it-tel_number is initial.
      html_new_line.
*     add_icon 'ICON_PHONE'.
*     add_icon 'ICON_PHONE_CALL_IN'.
      add_icon 'ICON_TELEPHONE_CALL'.
      concatenate
                  '<font size="4" color="0044FF">&nbsp;'
                   it-tel_number
                  '</font>'
             into  str_html
                   separated by space
                   .
      condense str_html.
      add_html_line str_html.
    endif.

*---Local phone number
    if not it-tel_extens is initial.
      html_new_line.
*     add_icon 'ICON_PHONE'.
      add_icon 'ICON_PHONE_CALL_IN'.
      concatenate
                  '<font size="2" color="0044FF">&nbsp;&nbsp;'
                  'Local phone'(354)
                   it-tel_extens
                  '</font>'
             into  str_html
                   separated by space
                   .
      condense str_html.
      add_html_line str_html.
    endif.
  else.
    concatenate
                '<font color="000000" size="1">'
                '<marquee bgcolor=#FFFFFF>'
*               '<marquee>'
                'The user not in selection. Sorry...'(376)
                '</marquee>'
                '<br><br>'
                '</font>'
           into  str_html
                 .
    condense str_html.
    add_html_line str_html.
  endif.

*-User's E-mail
  perform get_smtp_address using p_mandt v_bname
                        changing v_smtp_addr
                                 .
  if not v_smtp_addr is initial.
    html_new_line.
    html_new_line.
    html_underline.
    add_icon 'ICON_ENVELOPE_CLOSED'.
    condense v_smtp_addr.
    concatenate
                '<a href="mailto:'
                 v_smtp_addr
                '"><b>&nbsp'
                 v_smtp_addr
                '</b></a>'
           into  str_html
                 .
    condense str_html.
    add_html_line str_html.

    html_underline.
  endif.

*-Network resource with Users' Photos
* concatenate
*             '<br><br><br><br><br><br><br><a href="'
*              v_photos
*             '" target="_blank">'
*              v_photos
*             '</a>'
*        into  str_html
*              .
* condense str_html.
* add_html_line str_html.

  if not f_altbkgr is initial.
    modify_background.
  endif.

*-Display page
* check f_visible = '1'.
* get time field dd_t1.

*-Need distinguish the case, if used (for example) 46C SP level 24,
*      but it does not matter when used 46C Support Pack. level 52 :-\
  if ctrl_init is initial.
    ctrl_init = 'X'.
    call method dd->display_document
         exporting
*          reuse_control      = 'X'
*          reuse_registration = 'X'
*          container          =
           parent             =  dc
           .
  else.
    call method dd->display_document
         exporting
           reuse_control      = 'X'
           reuse_registration = 'X'
*          container          =
           parent             =  dc
           .
  endif.

* get time field dd_t2.

************************************************************************
***                                                                    *
***  The check is switched OFF because of alternative method needed    *
***               here to analyze GUI response time :-(                *
***                                                                    *
************************************************************************

*-Analyze runtime for display
* if dd_t2 > dd_t1.
*   dd_delta = dd_t2 - dd_t1.
* else.
*   dd_delta = dd_t1 - dd_t2.
* endif.

*-Bad response time, raise BAD RESOURCE flag
* if dd_delta > '000005'.
*   f_badres = 'X'.
* endif.

* message s031 with 'Processing time =' dd_delta. "Trace message
endform. "BUILD_DOCUMENT
*-----------------------------------------------------------------------
form toggle_visible using v_bname like usr02-bname.
*-Safety check
  if dc is initial.
    perform create_container.
    if dc is initial. exit. endif.
  endif.

*-Refresh document if outdated
  if v_bname <> last_html_bname.
    perform build_document using v_bname.
  endif.

*-Toggle visibility
  if f_visible = '0'. f_visible = '1'. else. f_visible = '0'. endif.
  call method dc->set_visible
       exporting
         visible           = f_visible
       exceptions
         cntl_error        = 1
         cntl_system_error = 2
         .
  case sy-subrc.
    when 0.
    when 1.
*     raise cntl_error.
      app_log_z2_1 '030' 'CNTRL_ERROR'.          "#EC NOTEXT
    when 2.
*     raise cntl_system_error.
      app_log_z2_1 '030' 'CNTRL_SYSTEM_ERROR'.   "#EC NOTEXT
  endcase.
endform. "TOGGLE_VISIBLE
*-----------------------------------------------------------------------
form dock_dc using v_side type i.
*-Safety check
  if dc is initial. exit. endif.

  call method dc->dock_at
       exporting
         side = v_side
         .
endform. "DOCK_DC
*-----------------------------------------------------------------------
form change_path_to_photos.
*-Check for active ARFC calls
  check_arfc.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  a_flds 'RSEUMOD'
         'EDIT_PATH'
         'Path to photos'(360)
          v_photos
          .
* clear ans.
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     = 'Set path to photos'(359)
         start_column    =  10
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'.
    r_flds 1 v_photos.
    if not last_html_bname is initial.
      perform build_document using last_html_bname.
    endif.
  endif.
  free fields.
endform. "CHANGE_PATH_TO_PHOTOS
*-----------------------------------------------------------------------
form change_path_to_phones.
*-Check for active ARFC calls
  check_arfc.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  a_flds 'RSEUMOD'
         'EDIT_PATH'
         'Path to phones'(370)
          p_phones
          .
* clear ans.
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     = 'Set path to phones'(369)
         start_column    =  10
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'.
    r_flds 1 p_phones.
    if p_upload is initial.
      confirm_step
        'Y'
        'Upload from external resource currently switched OFF'(371)
        'Do you want to switch this option ON right now?'(372)
        'External upload currently disabled'(373)
        .
      if ans = 'J'. p_upload = 'X'. endif.
    endif.

    perform upload_phones.
  endif.
  free fields.
endform. "CHANGE_PATH_TO_PHONES
*-----------------------------------------------------------------------
form change_background.
  constants
    hex_ciphers(16) value '0123456789ABCDEF'
  .
  data
    tmp_color like bg_color
  .
*-Check for active ARFC calls
  check_arfc.

*-Cleanup table FIELDS before use, cause it is global!
  cls fields.

  a_flds 'CYPRFOVR'
         'INSORDER'
         'Background'(380)
          bg_color
          .
* clear ans.
  call function 'POPUP_GET_VALUES'
       exporting
         no_value_check  = 'X'
         popup_title     = 'Set background color'(381)
         start_column    =  20
         start_row       =  7
       importing
         returncode      =  ans
       tables
         fields          =  fields
       exceptions
         error_in_fields =  1
         .
  check_wrong_fields.

  if ans <> 'A'.
    r_flds 1 tmp_color.
    translate tmp_color to upper case.                "#EC NOLANG
    if tmp_color co hex_ciphers.
      bg_color = tmp_color.
      if f_altbkgr is initial.
        confirm_step
          'Y'
          'Alternative background color currently switched OFF'(382)
          'Do you want to switch this option ON right now?'(372)
          'Alternative background currently disabled'(383)
          .
        if ans = 'J'. f_altbkgr = 'X'. endif.
      endif.

      if not last_html_bname is initial.
        perform build_document using last_html_bname.
      endif.
    else.
      app_log_z2_2 '031' text-384 hex_ciphers.
      message s031
         with 'Input must only contain hex ciphers'(384) hex_ciphers.
    endif.
  endif.
  free fields.
endform. "CHANGE_BACKGROUND
*-----------------------------------------------------------------------
form toggle_html_pane_main.
  if last_html_bname <> it-bname.
    perform build_document using it-bname.
    f_visible = '0'.
  endif.
  perform toggle_visible using it-bname.
endform. "TOGGLE_HTML_PANE_MAIN
*-----------------------------------------------------------------------
form toggle_badres.
  perform toggle_flag changing f_badres.

  if not last_html_bname is initial.
    perform build_document using last_html_bname.
  endif.

  if f_badres is initial.
    app_log_z2_2 '031' text-365 text-366.
    message s031
       with 'Attempts to access photo-resource'(365)
            'has been allowed'(366).
  else.
    app_log_z2_2 '031' text-365 text-367.
    message s031
       with 'Attempts to access photo-resource'(365)
            'has been disallowed'(367).
  endif.
endform. "TOGGLE_BADRES
*-----------------------------------------------------------------------
form toggle_altpict.
  perform toggle_flag changing f_altpict.

  if not last_html_bname is initial.
    perform build_document using last_html_bname.
  endif.

  if f_altpict is initial.
    app_log_z2_1 '030' text-374.
    message s030 with 'Standard photo will be used'(374).
  else.
    app_log_z2_1 '030' text-375.
    message s030 with 'Alternative photo will be used'(375).
  endif.
endform. "TOGGLE_ALTPICT
*-----------------------------------------------------------------------
form toggle_altbkgr.
  perform toggle_flag changing f_altbkgr.

  if not last_html_bname is initial.
    perform build_document using last_html_bname.
  endif.

  if f_altbkgr is initial.
    app_log_z2_1 '030' text-378.
    message s030 with 'Standard background color will be used'(378).
  else.
    app_log_z2_1 '030' text-379.
    message s030 with 'Alternative background color will be used'(379).
  endif.
endform. "TOGGLE_ALTBKGR
*-----------------------------------------------------------------------
form toggle_resize.
  perform toggle_flag changing f_resize.

  if not last_html_bname is initial.
    perform build_document using last_html_bname.
  endif.

  if f_resize is initial.
    app_log_z2_1 '030' text-385.
    message s030 with 'Original size of a photo will be used'(385).
  else.
    app_log_z2_1 '030' text-386.
    message s030 with 'Fixed size of a photo will be used'(386).
  endif.
endform. "TOGGLE_RESIZE
*-----------------------------------------------------------------------
form get_source_file.
  data tmp_path like rlgrap-filename.

  clear tmp_path.
  call function 'F4_FILENAME'
       exporting
         program_name  =  sy-cprog "sy-repid
         dynpro_number =  sy-dynnr
         field_name    = 'P_PHONES'
       importing
         file_name     =  tmp_path
         .
  if not p_upload is initial.
    move tmp_path to p_phones.
  endif.
endform. "GET_SOURCE_FILE
*----------------------------------------------------------------------
I000     Hint                                                                                                                                                                                                                                                                   5
I001     Message text                                                                                                                                                                                                                                                          15
I003     Last name                                                                                                                                                                                                                                                             15
I004     First name                                                                                                                                                                                                                                                            24
I005     Phone                                                                                                                                                                                                                                                                  9
I006     Local                                                                                                                                                                                                                                                                  5
I007     Users from the                                                                                                                                                                                                                                                        15
I008     Function                                                                                                                                                                                                                                                               8
I009     Users by selection criteria:                                                                                                                                                                                                                                          34
I010     @BF@Highlight entry for specified user                                                                                                                                                                                                                                41
I011     Client                                                                                                                                                                                                                                                                 6
I012     Locked users:                                                                                                                                                                                                                                                         13
I013     Department                                                                                                                                                                                                                                                            40
I015     Report                                                                                                                                                                                                                                                                 6
I016     client of system &                                                                                                                                                                                                                                                    18
I017     select desired options, then press the "Execute" or <F8> key                                                                                                                                                                                                          63
I018     Build.                                                                                                                                                                                                                                                                 7
I019     Room                                                                                                                                                                                                                                                                   5
I020     System                                                                                                                                                                                                                                                                 7
I021     Rel.                                                                                                                                                                                                                                                                   5
I022     Hostname                                                                                                                                                                                                                                                               9
I023     Completed by                                                                                                                                                                                                                                                          14
I024     Date                                                                                                                                                                                                                                                                   4
I025     Transaction                                                                                                                                                                                                                                                           11
I026     in background                                                                                                                                                                                                                                                         13
I027     Changed by                                                                                                                                                                                                                                                            12
I028     Date                                                                                                                                                                                                                                                                  10
I029     Time                                                                                                                                                                                                                                                                   8
I030     @44@Use high intensity colors                                                                                                                                                                                                                                         34
I031     @3V@Key field is always on the screen                                                                                                                                                                                                                                 55
I032     Time                                                                                                                                                                                                                                                                   5
I033     @MH@Single click instead of double when sorting list                                                                                                                                                                                                                  64
I034     Platform                                                                                                                                                                                                                                                               9
I035     (SU01 cannot be called)                                                                                                                                                                                                                                               23
I036     Selecting...                                                                                                                                                                                                                                                          15
I038     After &system & will not be available                                                                                                                                                                                                                                 40
I039     @15@Execute                                                                                                                                                                                                                                                           13
I040     Send popup message to user                                                                                                                                                                                                                                            32
I041     in client                                                                                                                                                                                                                                                             10
I042     Alert message to active users                                                                                                                                                                                                                                         43
I044     IP-address - Terminal name                                                                                                                                                                                                                                            36
I045     Term.ID                                                                                                                                                                                                                                                               10
I046     Server                                                                                                                                                                                                                                                                20
I047      Wastetime                                                                                                                                                                                                                                                            15
I048      hrs.                                                                                                                                                                                                                                                                  6
I049      min.                                                                                                                                                                                                                                                                  6
I050      sec.                                                                                                                                                                                                                                                                  6
I051     Sess                                                                                                                                                                                                                                                                   4
I053      Time                                                                                                                                                                                                                                                                  8
I054     Terminal                                                                                                                                                                                                                                                              20
I055     M                                                                                                                                                                                                                                                                      1
I057     La                                                                                                                                                                                                                                                                     2
I058     Transaction code                                                                                                                                                                                                                                                      20
I059     Transaction text                                                                                                                                                                                                                                                      36
I060     Password                                                                                                                                                                                                                                                               8
I061     Authentification                                                                                                                                                                                                                                                      16
I062     @IX@Help is available on the main screen too                                                                                                                                                                                                                          56
I063     (installation no. &)                                                                                                                                                                                                                                                  21
I064     RFC to DEV system                                                                                                                                                                                                                                                     25
I065     RFC to QAS system                                                                                                                                                                                                                                                     25
I066     RFC to PRD system                                                                                                                                                                                                                                                     25
I067     @42@                                                                                                                                                                                                                                                                   4
I069     @3X@                                                                                                                                                                                                                                                                   4
I073     Unsaved data will be lost                                                                                                                                                                                                                                             35
I074     Do you want to log off?                                                                                                                                                                                                                                               23
I075     Log Off                                                                                                                                                                                                                                                               16
I076     @8O@WARNING!!! This closes all of your sessions without saving                                                                                                                                                                                                        65
I078     @8O@and leaves the system! Any unsaved data will be lost!                                                                                                                                                                                                             65
I080     @33@Quit!                                                                                                                                                                                                                                                             10
I081     used by default                                                                                                                                                                                                                                                       25
I082     Incorrect logons per user: &                                                                                                                                                                                                                                          34
I083     List has been restricted according to sel. screen criteria                                                                                                                                                                                                            59
I084     @5A@Show terminal name without IP-address                                                                                                                                                                                                                             42
I085     @4G@Show selected users only                                                                                                                                                                                                                                          45
I086     [ description in language & not found ]                                                                                                                                                                                                                               39
I087     At first, switch filter ON                                                                                                                                                                                                                                            26
I088     Client restriction is OFF, shown entries for all clients                                                                                                                                                                                                              69
I089     Client restriction is ON, shown entries for client                                                                                                                                                                                                                    61
I090     to use this program                                                                                                                                                                                                                                                   31
I091     Do you want to clear                                                                                                                                                                                                                                                  20
I092     all log entries?                                                                                                                                                                                                                                                      19
I093     Clear log entries                                                                                                                                                                                                                                                     17
I094     Locked by Global Administrator                                                                                                                                                                                                                                        37
I095     Unknown status: USR02-UFLAG = &                                                                                                                                                                                                                                       35
I096     Logical system:                                                                                                                                                                                                                                                       15
I097     [ Not Defined ]                                                                                                                                                                                                                                                       17
I098     Delete obsolete entry from USR07                                                                                                                                                                                                                                      34
I099     Are you sure this entry is obsolete and need to be removed                                                                                                                                                                                                            58
I100     Warning!!!                                                                                                                                                                                                                                                            17
I101     Recipient's open sessions may crash on receiver-side timeout                                                                                                                                                                                                          70
I102     If recipient will not confirm the POPUP-message within                                                                                                                                                                                                                70
I103     seconds, then system may take him (her) out!!! (see 'rdisp/keepalive')                                                                                                                                                                                                70
I104     I know, what I do                                                                                                                                                                                                                                                     17
I105     Maybe next time...                                                                                                                                                                                                                                                    18
I106     @FC@Value for timer of unused TCP/IP-connections                                                                                                                                                                                                                      53
I107     Timer for check unused TCP/IP-connections                                                                                                                                                                                                                             41
I108     Confirm deletion                                                                                                                                                                                                                                                      22
I109     Entry in table USR07:                                                                                                                                                                                                                                                 23
I110     Compiled on                                                                                                                                                                                                                                                           13
I111     Search in user master records                                                                                                                                                                                                                                         40
I112     Search in roles (activity groups)                                                                                                                                                                                                                                     40
I113     Request to change user rights                                                                                                                                                                                                                                         29
I114     Switch language (partially)                                                                                                                                                                                                                                           27
I115     Refresh                                                                                                                                                                                                                                                                8
I116     ALV-standard                                                                                                                                                                                                                                                          40
I117     Display file with phones                                                                                                                                                                                                                                              40
I118     Display message log                                                                                                                                                                                                                                                   40
I119     Clear message log                                                                                                                                                                                                                                                     40
I120     Mark online users                                                                                                                                                                                                                                                     40
I121     Mark users with reference user                                                                                                                                                                                                                                        40
I122     Select all                                                                                                                                                                                                                                                            40
I123     Deselect all                                                                                                                                                                                                                                                          40
I124     Invert selection                                                                                                                                                                                                                                                      40
I125     Please choose a command for                                                                                                                                                                                                                                           27
I126     Execute command                                                                                                                                                                                                                                                       17
I127     TELNET or PING                                                                                                                                                                                                                                                        15
I128     telnet                                                                                                                                                                                                                                                                 6
I129     ping                                                                                                                                                                                                                                                                   4
I130     ( IP address =                                                                                                                                                                                                                                                        14
I131     No users of that kind were found                                                                                                                                                                                                                                      50
I132     Users with reference user were marked                                                                                                                                                                                                                                 50
I133     Online users were marked                                                                                                                                                                                                                                              50
I134     Limit on last logon (in days)                                                                                                                                                                                                                                         40
I135     Set scroll-boundary ON/OFF                                                                                                                                                                                                                                            40
I136     Do you want to run the program                                                                                                                                                                                                                                        30
I137     Top of extra sessions                                                                                                                                                                                                                                                 40
I138     *** hidden! ***                                                                                                                                                                                                                                                       15
I139     External RFC                                                                                                                                                                                                                                                          40
I140     Internal RFC                                                                                                                                                                                                                                                          40
I141     Go                                                                                                                                                                                                                                                                    40
I142     Cannot scroll list, rc =                                                                                                                                                                                                                                              32
I143     Application Server                                                                                                                                                                                                                                                    18
I144     Created by                                                                                                                                                                                                                                                            10
I145     Changed by                                                                                                                                                                                                                                                            10
I146     in system                                                                                                                                                                                                                                                              9
I147     in language                                                                                                                                                                                                                                                           11
I148     Build no.                                                                                                                                                                                                                                                              9
I149     Sel.-screen generated on                                                                                                                                                                                                                                              24
I150     at                                                                                                                                                                                                                                                                     2
I151     About program                                                                                                                                                                                                                                                         13
I152     Login not yet used in this client                                                                                                                                                                                                                                     40
I153     Users with unused logins were marked                                                                                                                                                                                                                                  40
I154     Mark users who have never been logged on                                                                                                                                                                                                                              40
I155     fragment                                                                                                                                                                                                                                                               8
I156     Previous                                                                                                                                                                                                                                                              40
I157     Next                                                                                                                                                                                                                                                                  40
I158     Display user address data                                                                                                                                                                                                                                             40
I159     Maintain user                                                                                                                                                                                                                                                         40
I160     Send message                                                                                                                                                                                                                                                          40
I161     Display spool requests                                                                                                                                                                                                                                                40
I164     Display all roles assigned to user                                                                                                                                                                                                                                    40
I165     Display authorization tree                                                                                                                                                                                                                                            40
I166     Hide additional buttons                                                                                                                                                                                                                                               40
I167     Show additional buttons                                                                                                                                                                                                                                               40
I168     Logon Date                                                                                                                                                                                                                                                            10
I169     Log.Time                                                                                                                                                                                                                                                               8
I171     Display allowed transactions                                                                                                                                                                                                                                          40
I172     Go to change documents                                                                                                                                                                                                                                                40
I180     Decrease                                                                                                                                                                                                                                                              40
I181     Increase                                                                                                                                                                                                                                                              40
I182     Time interval                                                                                                                                                                                                                                                         40
I183     Lower limit reached                                                                                                                                                                                                                                                   40
I184     Upper limit reached                                                                                                                                                                                                                                                   40
I185     Hide command line                                                                                                                                                                                                                                                     40
I186     Show command line                                                                                                                                                                                                                                                     40
I187     - found at line                                                                                                                                                                                                                                                       18
I188     - not found                                                                                                                                                                                                                                                           12
I189     - no more found                                                                                                                                                                                                                                                       20
I190     - unknown command. Type & for details.                                                                                                                                                                                                                                60
I191     List of commands                                                                                                                                                                                                                                                      16
I192     HELP      - this help                                                                                                                                                                                                                                                 72
I193     HIDE      - hide command line                                                                                                                                                                                                                                         72
I194     HIGHLIGHT - highligh option ON/OFF                                                                                                                                                                                                                                    72
I195     RANGE     - toggle search range: WIDE/NARROW                                                                                                                                                                                                                          72
I196     SCROLL    - scroll list to entry found ON/OFF                                                                                                                                                                                                                         72
I197     Command expected after &. Type & for details.                                                                                                                                                                                                                         60
I198     Kernel                                                                                                                                                                                                                                                                 6
I199     Res                                                                                                                                                                                                                                                                    3
I201     Cli                                                                                                                                                                                                                                                                    3
I202     User                                                                                                                                                                                                                                                                  12
I203     Terminal                                                                                                                                                                                                                                                              27
I212     Time                                                                                                                                                                                                                                                                   8
I213     Stoppage                                                                                                                                                                                                                                                               8
I220     Cannot access                                                                                                                                                                                                                                                         13
I221     SM51                                                                                                                                                                                                                                                                  40
I222     SM66                                                                                                                                                                                                                                                                  40
I223     Debug ABAP                                                                                                                                                                                                                                                            40
I224     B-type: Dialog-free communications within one system                                                                                                                                                                                                                  57
I225     C-type: Dialog-free communications between systems                                                                                                                                                                                                                    50
I226     Mass password reset is only allowed in EXPERT mode                                                                                                                                                                                                                    50
I227     for ALL selected users? ATTENTION!!!                                                                                                                                                                                                                                  50
I228     Available functions for account                                                                                                                                                                                                                                       36
I229     Display Z-roles assigned to user                                                                                                                                                                                                                                      40
I230     FASTFIND  - paste and search immediately ON/OFF                                                                                                                                                                                                                       72
I231     Mark by surname, click to change                                                                                                                                                                                                                                      40
I232     Mark by username, click to change                                                                                                                                                                                                                                     40
I255     SHOWMODE  - import mode indicator ON/OFF                                                                                                                                                                                                                              72
I256     Command processed                                                                                                                                                                                                                                                     40
I257     No more found. Total:                                                                                                                                                                                                                                                 30
I258     DISABLE   - disable commands                                                                                                                                                                                                                                          72
I259     CMD!      - switch between command mode/search mode                                                                                                                                                                                                                   72
I260     Commands disabled. Type CMDD in OK-code to enable.                                                                                                                                                                                                                    50
I261     Threshold date is                                                                                                                                                                                                                                                     17
I262     AUTOSCAN  - autoscan option ON/OFF                                                                                                                                                                                                                                    72
I263     AUTOCROP  - autocrop option ON/OFF                                                                                                                                                                                                                                    72
I264     MARK      - switch to mark mode                                                                                                                                                                                                                                       72
I265     FILTER    - switch to filter mode                                                                                                                                                                                                                                     72
I266     SEARCH    - switch to search mode                                                                                                                                                                                                                                     72
I267     ******************* GENERAL COMMANDS *******************                                                                                                                                                                                                              72
I268     WIDE      - set wide scan range: BNAME .. ROOMNUMBER                                                                                                                                                                                                                  72
I269     ***************** SOME SPECIAL SWITCHES ****************                                                                                                                                                                                                              72
I270     User without address data                                                                                                                                                                                                                                             40
I271     * Out of command mode prefix & is required for commands                                                                                                                                                                                                               72
I272     NARROW    - set narrow scan range: BNAME .. NAME_LAST                                                                                                                                                                                                                 72
I273     EXIT      - quit command mode                                                                                                                                                                                                                                         72
I274     CMD       - switch to command mode                                                                                                                                                                                                                                    72
I275     Users without address data were marked                                                                                                                                                                                                                                50
I276     users without address data                                                                                                                                                                                                                                            40
I277     Entered value is too big                                                                                                                                                                                                                                              40
I278     Users locked by administator were marked                                                                                                                                                                                                                              70
I279     Users locked by incorrect logons were marked                                                                                                                                                                                                                          70
I280     Users with last reg. <= & were marked                                                                                                                                                                                                                                 70
I281     Users created after & were marked                                                                                                                                                                                                                                     70
I282     Users with empty class (security group) were marked                                                                                                                                                                                                                   70
I283     Users with type other than A were marked                                                                                                                                                                                                                              70
I284     ******************* SELECTION COMMANDS *****************                                                                                                                                                                                                              72
I285     ****************** PROCESSING COMMANDS *****************                                                                                                                                                                                                              72
I286     OLD       - users with reg. date <= &                                                                                                                                                                                                                                 72
I287     NEW       - users created from &                                                                                                                                                                                                                                      72
I288     ERR       - users with incorrect logons                                                                                                                                                                                                                               72
I289     NOADDR    - users without address data (if enabled)                                                                                                                                                                                                                   72
I290     NOCLASS   - users without security group (USR02-CLASS)                                                                                                                                                                                                                72
I291     LOCKED    - locked users                                                                                                                                                                                                                                              72
I292     LOCKEDADM - users locked by administrator                                                                                                                                                                                                                             72
I293     LOCKEDERR - users locked by incorrect logons                                                                                                                                                                                                                          72
I294     REFR      - refresh list                                                                                                                                                                                                                                              72
I295     EXCL      - exclude marked entries from list                                                                                                                                                                                                                          72
I296     CROP      - crop list (display marked entries only)                                                                                                                                                                                                                   72
I297     NOTUSED   - unused logins                                                                                                                                                                                                                                             72
I300     DATE      - report threshold date                                                                                                                                                                                                                                     72
I301     Submit                                                                                                                                                                                                                                                                 6
I302     This takes a several minutes                                                                                                                                                                                                                                          28
I303     Start program                                                                                                                                                                                                                                                         16
I304     Run the program                                                                                                                                                                                                                                                       19
I305     Kill all sessions of the user                                                                                                                                                                                                                                         37
I306     Kick the user out                                                                                                                                                                                                                                                     23
I307     NONDIA    - users with type other than A                                                                                                                                                                                                                              72
I308     LANG      - switch language                                                                                                                                                                                                                                           72
I311     Threshold date must NOT be in the future                                                                                                                                                                                                                              40
I312     SETDATE   - set threshold date                                                                                                                                                                                                                                        72
I313     KEEP      - toggle hold entries option ON/OFF                                                                                                                                                                                                                         72
I314     Turn filtration keeping OFF                                                                                                                                                                                                                                           40
I315     Turn filtration keeping ON                                                                                                                                                                                                                                            40
I316     LINKED    - users with reference users                                                                                                                                                                                                                                72
I317     ALL       - mark all users                                                                                                                                                                                                                                            72
I318     NONE      - unmark all users                                                                                                                                                                                                                                          72
I319     INV       - invert selection                                                                                                                                                                                                                                          72
I320     DEBUG     - turn ABAP-debugger ON                                                                                                                                                                                                                                     72
I321     Exclude marked entries from list                                                                                                                                                                                                                                      40
I322     Check for missing addresses is ON                                                                                                                                                                                                                                     40
I323     Check for missing addresses is OFF                                                                                                                                                                                                                                    40
I324     Filter entries containing substring                                                                                                                                                                                                                                   40
I325     Mark entries containing substring                                                                                                                                                                                                                                     40
I326     Search entry containing substring                                                                                                                                                                                                                                     40
I327     Process command                                                                                                                                                                                                                                                       40
I328     EXP       - copy marked users to clipboard                                                                                                                                                                                                                            72
I329     IMP       - mark users from clipboard                                                                                                                                                                                                                                 72
I330     @JH@ Search mode (jump to entry found)                                                                                                                                                                                                                                70
I331     @8G@ Mark mode (mark found entries)                                                                                                                                                                                                                                   70
I332     @4G@ Filter mode (filter found entries)                                                                                                                                                                                                                               70
I333     @AJ@ Command mode (command execution)                                                                                                                                                                                                                                 70
I334     Doubleclick command line to get list of commands                                                                                                                                                                                                                      70
I335     Choose one of available modes                                                                                                                                                                                                                                         40
I336     Note that you may execute a command in any mode                                                                                                                                                                                                                       70
I337     just typing it in command line with special prefix &                                                                                                                                                                                                                  70
I338     Set narrow search area                                                                                                                                                                                                                                                40
I339     Set wide search area                                                                                                                                                                                                                                                  40
I340     EXCEL     - export data to Microsoft Excel                                                                                                                                                                                                                            72
I341     Export data to Microsoft Excel                                                                                                                                                                                                                                        40
I342     The function is not implemented for Java environment                                                                                                                                                                                                                  52
I345     Date of last password change                                                                                                                                                                                                                                          40
I346     days past                                                                                                                                                                                                                                                             15
I347     --.--.----                                                                                                                                                                                                                                                            10
I348     Password reset?                                                                                                                                                                                                                                                       16
I349     Password changed                                                                                                                                                                                                                                                      16
I350     Account had not been used in the client!                                                                                                                                                                                                                              40
I351     You have not sufficient privilegies                                                                                                                                                                                                                                   35
I352     to lock/unlock these users                                                                                                                                                                                                                                            50
I353     Class                                                                                                                                                                                                                                                                  5
I354     Local phone                                                                                                                                                                                                                                                           15
I355     Photo                                                                                                                                                                                                                                                                  5
I356     Full path to shared resource must be set in table                                                                                                                                                                                                                     50
I357     under key                                                                                                                                                                                                                                                             10
I358     , for example: \\server1\R3photos\                                                                                                                                                                                                                                    34
I359     Set path to photos                                                                                                                                                                                                                                                    40
I360     Path to photos                                                                                                                                                                                                                                                        18
I361     access to resource                                                                                                                                                                                                                                                    18
I362     has been disabled to prevent connection problem.                                                                                                                                                                                                                      53
I363     To reenable connection attempts again, please enter                                                                                                                                                                                                                   53
I364     CONN in OK-code.                                                                                                                                                                                                                                                      16
I365     Attempts to access photo-resource                                                                                                                                                                                                                                     80
I366     have been allowed                                                                                                                                                                                                                                                     17
I367     have been disallowed                                                                                                                                                                                                                                                  20
I368     (you can disable it by entering CONN in OK-code)                                                                                                                                                                                                                      54
I369     Set path to phones                                                                                                                                                                                                                                                    40
I370     Path to phones                                                                                                                                                                                                                                                        18
I371     Upload from external resource currently switched OFF                                                                                                                                                                                                                  70
I372     Do you want to switch this option ON right now?                                                                                                                                                                                                                       70
I373     External upload currently disabled                                                                                                                                                                                                                                    40
I374     Standard photo will be used                                                                                                                                                                                                                                           40
I375     Alternative photo will be used                                                                                                                                                                                                                                        40
I376     The user not in selection. Sorry...                                                                                                                                                                                                                                   40
I377     To change path to resource, enter PATH                                                                                                                                                                                                                                42
I378     Standard background color will be used                                                                                                                                                                                                                                60
I379     Alternative background color will be used                                                                                                                                                                                                                             60
I380     Background                                                                                                                                                                                                                                                            40
I381     Set background color                                                                                                                                                                                                                                                  40
I382     Alternative background color currently switched OFF                                                                                                                                                                                                                   60
I383     Alternative background currently disabled                                                                                                                                                                                                                             60
I384     Input must only contain hex ciphers                                                                                                                                                                                                                                   40
I385     Original size of a photo will be used                                                                                                                                                                                                                                 70
I386     Fixed size of a photo will be used                                                                                                                                                                                                                                    70
I387     @2V@Paste                                                                                                                                                                                                                                                              9
I388     @K2@Display command line window                                                                                                                                                                                                                                       54
I389     @4O@Copy username when doubleclick surname                                                                                                                                                                                                                            54
I390     Copy username when doubleclick surname is ON                                                                                                                                                                                                                          50
I391     Copy username when doubleclick surname is OFF                                                                                                                                                                                                                         50
I392     @8G@Add                                                                                                                                                                                                                                                               12
I393     Empty value was copied to the buffer                                                                                                                                                                                                                                  40
I394     was copied to the buffer                                                                                                                                                                                                                                              40
I395     Navigation mode is active                                                                                                                                                                                                                                             40
I396     Quick copy mode is active                                                                                                                                                                                                                                             40
I397     Choose mode                                                                                                                                                                                                                                                           40
I398     Command line is empty                                                                                                                                                                                                                                                 40
I400     Single statistical records                                                                                                                                                                                                                                            26
I402     Program                                                                                                                                                                                                                                                                9
I403     Screen number                                                                                                                                                                                                                                                         13
I404     Resp. time (ms) >=                                                                                                                                                                                                                                                    20
I405     DB req time (ms) >=                                                                                                                                                                                                                                                   20
I407     Since time (hhmmss)                                                                                                                                                                                                                                                   19
I408     Since day (incl.)                                                                                                                                                                                                                                                     17
I411     Seq. stat. dataset name                                                                                                                                                                                                                                               23
I412     Max. number of shown entries                                                                                                                                                                                                                                          28
I415     Create slave on terminal                                                                                                                                                                                                                                              24
I417     Terminal ID                                                                                                                                                                                                                                                           15
I418     Extension                                                                                                                                                                                                                                                             10
I419     Change extension for media content                                                                                                                                                                                                                                    40
I420     Support Package Manager version                                                                                                                                                                                                                                       40
I421     Call SPAM                                                                                                                                                                                                                                                             40
I422     Refresh                                                                                                                                                                                                                                                               40
I423     Do you want to leave this screen                                                                                                                                                                                                                                      70
I424     Press Yes to confirm                                                                                                                                                                                                                                                  70
I500     incorrect fields                                                                                                                                                                                                                                                      17
I555     PAGE mem.                                                                                                                                                                                                                                                             10
I556     ROLL mem.                                                                                                                                                                                                                                                             10
I558     Mem.(sum)                                                                                                                                                                                                                                                             10
I559     PRIV mem.                                                                                                                                                                                                                                                             10
I666     Calling transaction                                                                                                                                                                                                                                                   19
I667     Extend                                                                                                                                                                                                                                                                 9
I668     Squeeze                                                                                                                                                                                                                                                                7
I700     disconn. by:                                                                                                                                                                                                                                                          12
I751     DEV                                                                                                                                                                                                                                                                    3
I752     QAS                                                                                                                                                                                                                                                                    3
I753     PRD                                                                                                                                                                                                                                                                    3
I771     =====================================================                                                                                                                                                                                                                 53
I772     @BF@Expert mode is required for additional abilities                                                                                                                                                                                                                  52
I773     such as submitting some statistical reports                                                                                                                                                                                                                           43
I774     and more. Enter password and get ALL of the power!                                                                                                                                                                                                                    50
I775     Number of hits can't be negative                                                                                                                                                                                                                                      44
I776     Kernel Release and Patch Level                                                                                                                                                                                                                                        40
I777     View history of reg. failures                                                                                                                                                                                                                                         40
I778     ?Subject=Info from SAP R/3 user                                                                                                                                                                                                                                       32
I779     &Body=Hello                                                                                                                                                                                                                                                           19
I780     Do you want to reset password                                                                                                                                                                                                                                         29
I781     for user                                                                                                                                                                                                                                                              12
I782     Reset password                                                                                                                                                                                                                                                        14
I783     Do you want to continue with server                                                                                                                                                                                                                                   35
I784     Go to remote server                                                                                                                                                                                                                                                   19
I785     You are already logged on server                                                                                                                                                                                                                                      32
I786     @1C@Send this message to users                                                                                                                                                                                                                                        50
I787     Confirm multiple sending                                                                                                                                                                                                                                              31
I788     Server name                                                                                                                                                                                                                                                           11
I790     Error receiving ARFC task results                                                                                                                                                                                                                                     70
I791     Copy & to                                                                                                                                                                                                                                                             40
I792     Cannot continue: ARFC call still active                                                                                                                                                                                                                               60
I793     Destination: client                                                                                                                                                                                                                                                   19
I794     on server                                                                                                                                                                                                                                                             10
I795     authorizations were added. Please relogon into R/3 system.                                                                                                                                                                                                            60
I796     authorizations were added. It takes effect immediately.                                                                                                                                                                                                               55
I797     IP address                                                                                                                                                                                                                                                            15
I798     Turn autorefresh OFF                                                                                                                                                                                                                                                  40
I799     Turn autorefresh ON                                                                                                                                                                                                                                                   40
I800     There are no transaction code associated with                                                                                                                                                                                                                         45
I801     @45@Miscellaneous                                                                                                                                                                                                                                                     17
I802     @MS@Layout                                                                                                                                                                                                                                                            15
I803     @BY@Expert                                                                                                                                                                                                                                                            11
I804     @42@Refresh list on return from called transaction                                                                                                                                                                                                                    59
I805     @43@Jump directly to active user list                                                                                                                                                                                                                                 49
I806     @4G@Filter                                                                                                                                                                                                                                                            10
I807     @KW@A - Dialog                                                                                                                                                                                                                                                        14
I808     @KX@B - System user (internal RFC and bgr. process.)                                                                                                                                                                                                                  60
I809     @KY@C - Communication user (external RFC)                                                                                                                                                                                                                             51
I810     @KZ@L - Reference user                                                                                                                                                                                                                                                31
I811     @L0@S - Service user                                                                                                                                                                                                                                                  31
I813     @DZ@Do not fill E-mail header and body                                                                                                                                                                                                                                53
I814     View source                                                                                                                                                                                                                                                           15
I815     @3R@Show memory details                                                                                                                                                                                                                                               34
I816     @32@Start transactions in new mode                                                                                                                                                                                                                                    37
I817     Last Registered Auth. Failure                                                                                                                                                                                                                                         34
I818     @38@Search an entry in tab. USR07 for a user                                                                                                                                                                                                                          46
I819     @2Y@At new selection - scroll list to first page                                                                                                                                                                                                                      50
I821     Can not open file with phones                                                                                                                                                                                                                                         36
I822     Can not read file with phones                                                                                                                                                                                                                                         38
I824     @BH@Propose value (Now - 2 hours) as STAT's start time                                                                                                                                                                                                                54
I827     Go to this server                                                                                                                                                                                                                                                     22
I828     Application Log                                                                                                                                                                                                                                                       16
I829     Creator                                                                                                                                                                                                                                                               12
I830     Creat.Date                                                                                                                                                                                                                                                            10
I831     Pointer is set to user                                                                                                                                                                                                                                                23
I837     @6L@Other  sessions:                                                                                                                                                                                                                                                  20
I838     @CR@Zombie sessions:                                                                                                                                                                                                                                                  20
I839     @BW@RFC connections:                                                                                                                                                                                                                                                  20
I840     RFC connections/others                                                                                                                                                                                                                                                22
I841     Type                                                                                                                                                                                                                                                                   4
I849     GUI vers.                                                                                                                                                                                                                                                             10
I850     C.Type                                                                                                                                                                                                                                                                 6
I851     Status                                                                                                                                                                                                                                                                 9
I852     Dia.Time                                                                                                                                                                                                                                                               8
I853     GUI                                                                                                                                                                                                                                                                    6
I854     RFC                                                                                                                                                                                                                                                                    6
I855     Plugin                                                                                                                                                                                                                                                                 6
I856     Connected                                                                                                                                                                                                                                                              9
I857     Zombie                                                                                                                                                                                                                                                                 9
I858     Pooled                                                                                                                                                                                                                                                                 9
I859     IP not detected                                                                                                                                                                                                                                                       15
I860     Act                                                                                                                                                                                                                                                                    3
I861     Message from user                                                                                                                                                                                                                                                     25
I862     Best Regards,                                                                                                                                                                                                                                                         13
I863     Please choose a mailing program                                                                                                                                                                                                                                       31
I864     that you want to be used here                                                                                                                                                                                                                                         35
I866     Send E-mail to &                                                                                                                                                                                                                                                      18
I867     @00@ SAPOffice cannot be used for client &                                                                                                                                                                                                                            44
I868     @DZ@ SAPOffice -> &                                                                                                                                                                                                                                                   19
I869     @E2@ External program &                                                                                                                                                                                                                                               24
I870     <E-mail unknown>                                                                                                                                                                                                                                                      19
I871     Send error                                                                                                                                                                                                                                                            15
I872     Sending cancelled                                                                                                                                                                                                                                                     17
I873     Unknown error encountered                                                                                                                                                                                                                                             28
I874     The program hasn't a selection-screen, so that may not be safe!!!                                                                                                                                                                                                     70
I875     Run                                                                                                                                                                                                                                                                    9
I876     Display                                                                                                                                                                                                                                                               11
I877     Run the program (NOT SAFE) or display its source code (RECOMMENDED)?                                                                                                                                                                                                  70
I878     Please choose:                                                                                                                                                                                                                                                        15
I879     With AUTHS                                                                                                                                                                                                                                                            10
I880     With S_TCODE                                                                                                                                                                                                                                                          12
I881     Display authorizations                                                                                                                                                                                                                                                22
I882     Build:                                                                                                                                                                                                                                                                 7
I883     Client must have a numeric value                                                                                                                                                                                                                                      38
I884     Get information about code pages and NLS locale                                                                                                                                                                                                                       55
I885     Want to display source code of the program                                                                                                                                                                                                                            42
I886     Navigation confirmation                                                                                                                                                                                                                                               23
I887     With incorrect logons:                                                                                                                                                                                                                                                23
I888     The user &1 has reference to user &2                                                                                                                                                                                                                                  70
I889     That is, he or she has all of authorizations of reference user (add.).                                                                                                                                                                                                70
I890     Would you like to...                                                                                                                                                                                                                                                  70
I891     @13@ Find all users linked to user &                                                                                                                                                                                                                                  70
I892     @CQ@ Find all users linked to user &                                                                                                                                                                                                                                  70
I893     @CR@ Remove reference to user &                                                                                                                                                                                                                                       70
I894     &1 linked to user &2                                                                                                                                                                                                                                                  40
I895     Users with incorrect logon attempts were marked                                                                                                                                                                                                                       50
I896     Locked users were marked                                                                                                                                                                                                                                              50
I897     Inplace toolbar                                                                                                                                                                                                                                                       19
I898     Export to clipboard                                                                                                                                                                                                                                                   22
I899     Import from clipboard                                                                                                                                                                                                                                                 23
I900     Last logon                                                                                                                                                                                                                                                            10
I901     Time reg                                                                                                                                                                                                                                                               8
I902     Days from last logon                                                                                                                                                                                                                                                  20
I903     Enter threshold value                                                                                                                                                                                                                                                 26
I906     Security violation                                                                                                                                                                                                                                                    24
I908     Refresh-on-Return: Deactivated                                                                                                                                                                                                                                        35
I909     Refresh-on-Return: Activated                                                                                                                                                                                                                                          35
I910     Launch transaction                                                                                                                                                                                                                                                    18
I911     Do you want to launch transaction                                                                                                                                                                                                                                     33
I913     NotAvail                                                                                                                                                                                                                                                               8
I914     link active ---->                                                                                                                                                                                                                                                     20
I915     Locked by Administrator                                                                                                                                                                                                                                               26
I916     Locked due to incorrect logon                                                                                                                                                                                                                                         46
I917     You really want to lock yourself account                                                                                                                                                                                                                              52
I918     Self-locking confirmation                                                                                                                                                                                                                                             28
I919     Do you want to force processing with user                                                                                                                                                                                                                             41
I920     Launch VNC                                                                                                                                                                                                                                                            10
I921     Do you want to launch VNC for                                                                                                                                                                                                                                         29
I922     Ignore Locks                                                                                                                                                                                                                                                          24
I923     Clear                                                                                                                                                                                                                                                                 12
I924     Preset                                                                                                                                                                                                                                                                12
I925     @LX@Open this tabstrip when the selection screen is called                                                                                                                                                                                                            58
I926     Connecting to                                                                                                                                                                                                                                                         13
I927     Echo ON/OFF confirmation                                                                                                                                                                                                                                              39
I928     Continue anyway?                                                                                                                                                                                                                                                      21
I929     This feature works unstable on SAP Release                                                                                                                                                                                                                            51
I930     Other server...                                                                                                                                                                                                                                                       16
I931     RFC-jump to:                                                                                                                                                                                                                                                          15
I932     Extra server:                                                                                                                                                                                                                                                         18
I933     Int                                                                                                                                                                                                                                                                    3
I934     Ext                                                                                                                                                                                                                                                                    3
I935     Preview for servers which name differs with my                                                                                                                                                                                                                        50
I936     Cannot get this information due to error #                                                                                                                                                                                                                            42
I937     [not enough data to get description]                                                                                                                                                                                                                                  36
I938     [    unknown transaction code      ]                                                                                                                                                                                                                                  36
I939     Filter for SM50, SM04, SM12 is ON                                                                                                                                                                                                                                     40
I940     Filter for SM50, SM04, SM12 is OFF                                                                                                                                                                                                                                    40
I942     Choose action for                                                                                                                                                                                                                                                     21
I943     @2U@Copy <                                                                                                                                                                                                                                                            16
I944     @F8@View personal info                                                                                                                                                                                                                                                32
I945     @CQ@Find users linked to                                                                                                                                                                                                                                              24
I946     @96@Show spool for the last 30 days                                                                                                                                                                                                                                   39
I947     @BA@Clear password history                                                                                                                                                                                                                                            28
I948     @11@Delete user... (check linked)                                                                                                                                                                                                                                     40
I949     Other users have reference to                                                                                                                                                                                                                                         32
I950     link(s) found. Continue anyway?                                                                                                                                                                                                                                       37
I951     There are links from other users                                                                                                                                                                                                                                      33
I952     @MG@Only available in client                                                                                                                                                                                                                                          30
I953     @00@E-mail not found                                                                                                                                                                                                                                                  20
I954     Reset password history for user                                                                                                                                                                                                                                       37
I955     Reset password history                                                                                                                                                                                                                                                22
I956     Password history cleared for                                                                                                                                                                                                                                          28
I957     @MG@No authorization for this action                                                                                                                                                                                                                                  36
I958     users are linked to                                                                                                                                                                                                                                                   26
I959     No linked users were found for                                                                                                                                                                                                                                        34
I960     Hide                                                                                                                                                                                                                                                                   6
I961     Show                                                                                                                                                                                                                                                                   8
I962     Show memory consumpted by this user                                                                                                                                                                                                                                   42
I964     @1T@Last Logon (all clients, date/time in descending order)                                                                                                                                                                                                           59
I965     User had never been logged on into this client!                                                                                                                                                                                                                       52
I966     Password for this user was probably reset?                                                                                                                                                                                                                            43
I967     @38@Check for current status of ST01 switches                                                                                                                                                                                                                         46
I968     @4G@Filter output on specified user                                                                                                                                                                                                                                   48
I969     Trace is switched off. Cannot read switches.                                                                                                                                                                                                                          44
I970     ST01 - trace currently disabled                                                                                                                                                                                                                                       31
I971     Authorization check is not active!                                                                                                                                                                                                                                    34
I972     Run report anyway?                                                                                                                                                                                                                                                    20
I973     Levels of installed components (Support Packages)                                                                                                                                                                                                                     63
I974     Support Packages Info                                                                                                                                                                                                                                                 30
I975     Crop list (display marked entries only)                                                                                                                                                                                                                               40
I976     Mass popup sending (&)                                                                                                                                                                                                                                                35
I977     Errors during POPUP sending (&)                                                                                                                                                                                                                                       40
I978     List has not been restricted                                                                                                                                                                                                                                          30
I979     Do you want to unlock selected users?                                                                                                                                                                                                                                 40
I980     Do you want to lock selected users?                                                                                                                                                                                                                                   40
I981     Note: Special users will be excluded!                                                                                                                                                                                                                                 40
I982     Mass locking/unlocking                                                                                                                                                                                                                                                40
I983     Maintenance of some users is not possible now.                                                                                                                                                                                                                        60
I984     These users will be excluded from further processing.                                                                                                                                                                                                                 60
I985     is processing by user                                                                                                                                                                                                                                                 28
I986     Do you want to unlock user                                                                                                                                                                                                                                            27
I987     Do you want to lock user                                                                                                                                                                                                                                              24
I988     Lock/unlock user                                                                                                                                                                                                                                                      24
I989     - Lock state not changed                                                                                                                                                                                                                                              28
I990     @BW@Count RFC connections, Plugins and others                                                                                                                                                                                                                         45
I991     Installed SAP licenses (saplicense -show)                                                                                                                                                                                                                             45
I992     User limit                                                                                                                                                                                                                                                            10
I993     Show SAP Release information                                                                                                                                                                                                                                          28
I994     Show SAP licenses                                                                                                                                                                                                                                                     21
I995     Field catalog merge error =                                                                                                                                                                                                                                           31
I996     ALV POPUP error =                                                                                                                                                                                                                                                     18
I997     RetCode                                                                                                                                                                                                                                                                9
I998     Upload from                                                                                                                                                                                                                                                           11
I999     @KM@Upload phones from file on network resource                                                                                                                                                                                                                       51
R        Administration: user monitor                                                                                                                                                                                                                                          28
SP_APPCP         Character set (AppServer)                                                                                                                                                                                                                                     33
SP_CDAT  D       Created on                                                                                                                                                                                                                                                    18
SP_CHKPAR        Check value 'rdisp/keepalive'                                                                                                                                                                                                                                 37
SP_CMD           Display command line                                                                                                                                                                                                                                          28
SP_CNAM  D       Created by                                                                                                                                                                                                                                                    18
SP_CPYNAM        Quick copy to clipboard                                                                                                                                                                                                                                       31
SP_DEFTAB        Use as default tabstip                                                                                                                                                                                                                                        30
SP_DETAIL        User's context                                                                                                                                                                                                                                                29
SP_EXTRA         Look for RFC connections                                                                                                                                                                                                                                      32
SP_FAIL          Check for Auth. Failure                                                                                                                                                                                                                                       33
SP_GUICP         Character set (SAPGUI)                                                                                                                                                                                                                                        30
SP_HOST  D       Host                                                                                                                                                                                                                                                          12
SP_HOT           Single click                                                                                                                                                                                                                                                  24
SP_ICON1         Icon: User on this AppServ                                                                                                                                                                                                                                    36
SP_ICON2         Icon: User on other AppServ                                                                                                                                                                                                                                   38
SP_INTENS        Contrast scheme                                                                                                                                                                                                                                               25
SP_JUMP          Auto-jump to SESSIONS                                                                                                                                                                                                                                         29
SP_LANG  D       Original language                                                                                                                                                                                                                                             25
SP_LOCALE        NLS locale                                                                                                                                                                                                                                                    18
SP_MANDT D       Client                                                                                                                                                                                                                                                        15
SP_MATCH         Filtered active sessions                                                                                                                                                                                                                                      32
SP_NEWMOD        Transactions in new mode                                                                                                                                                                                                                                      32
SP_NOFILL        Create empty E-mail                                                                                                                                                                                                                                           31
SP_NO_IP         Hide IP-addresses                                                                                                                                                                                                                                             26
SP_PERIOD        Limit on last logon (in days)                                                                                                                                                                                                                                 37
SP_PHONES        Path to flat file with phones                                                                                                                                                                                                                                 37
SP_POINT         Pointer                                                                                                                                                                                                                                                       17
SP_PRN           Colors for printer                                                                                                                                                                                                                                            26
SP_PWD           Expert mode                                                                                                                                                                                                                                                   21
SP_REFR          Refresh-on-Return                                                                                                                                                                                                                                             29
SP_REPID D       Report name                                                                                                                                                                                                                                                   19
SP_RETURN        Back to first page                                                                                                                                                                                                                                            33
SP_ROWS  D       Maximum no. of hits                                                                                                                                                                                                                                           27
SP_SCR           Colors for screen                                                                                                                                                                                                                                             25
SP_SCROLL        Smart scrolling                                                                                                                                                                                                                                               23
SP_SDAT  D       Standard selection screen gene                                                                                                                                                                                                                                38
SP_SILENT        Without confirmation                                                                                                                                                                                                                                          28
SP_SRCSY D       Original system                                                                                                                                                                                                                                               23
SP_STAT2H        Preset start time for STAT                                                                                                                                                                                                                                    37
SP_STIM          Time                                                                                                                                                                                                                                                          12
SP_SWST01        Check for trace status                                                                                                                                                                                                                                        36
SP_TIME          System time                                                                                                                                                                                                                                                   23
SP_UDAT  D       Last changed on                                                                                                                                                                                                                                               23
SP_UNAM  D       Last changed by                                                                                                                                                                                                                                               23
SP_UPLOAD        Upload phones from PC-file                                                                                                                                                                                                                                    36
SP_USFILT        Filter for SM50, SM04, SM12                                                                                                                                                                                                                                   35
SP_VERN  D       Version number                                                                                                                                                                                                                                                22
SSO_BNAMED       User                                                                                                                                                                                                                                                          20
SSO_CLASS        Group for authorization                                                                                                                                                                                                                                       32
SSO_GROUP        User group (general)                                                                                                                                                                                                                                          28
SSO_USTYPD       User type                                                                                                                                                                                                                                                     24
